Commands and Strings

There is a complete documentation of Octave at http://www.gnu.org/software/octave/doc/interpreter/

Formatting numbers

You can format numbers in three different ways; format long, format short and format bank (2 decimals)

>>> format long
>>> pi
ans = 3.14159265358979
>>> format short
>>> pi
ans = 3.1416
>>> format bank
>>> pi
ans = 3.14 

Just writing the command format will give you the default format short.

String variables

When handling text instead of numbers you use strings. A string is enclosed in either "-signs or '-signs.

>>> my_string_variable="Hello World!"
my_string_variable = Hello World!
>>> my_string_variable='Hello World!'
my_string_variable = Hello World! 

The help command

If you want to find information about a command or a function you can use the help command.

>>> help asin
`asin' is a built-in function

-- Mapping Function: asin (X)

Compute the inverse sine in radians for each element of X.

See also: sin, asind

The disp command

You can use the disp command together with an argument enclosed in brackets to display data. When using disp the output is displayed without the ans=.

>>> disp(pi)
3.1416
>>> disp(my_string_variable)
Hello World!
>>> disp("The value of pi is:"), disp(pi)
The value of pi is:
3.1416 

Date and time

When measuring time on a computer it is a convention to measure the time since 00:00:00 UTC 1 January 1970. The command time will give you the number of seconds since then; the command now will give you the number of days. The command date will give you the current date as a string. The command clock will give you the current year-month-day-hour-minute-second as a row-matrix.

>>> time
ans = 1.2737e+009
>>> now
ans = 7.3427e+005
>>> date
ans = 12-May-2010
>>> clock
ans =

2010.0000 5.0000 12.0000 15.0000 41.0000 40.3795

by Malin Christersson under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 Sweden License