You are on page 1of 3

Octave Quick Reference Octave Version 1.

0 Killing and Yanking Strings and Common Escape Sequences


kill to the end of the line A string constant consists of a sequence of characters enclosed
Starting Octave
C-k
C-y yank the most recently killed text in either double-quote or single-quote marks.
octave start interactive Octave session M-d kill to the end of the current word \\ a literal backslash
octave le run Octave on commands in le M-DEL kill the word behind the cursor \" a literal double-quote character
octave --help describe command line options M-y rotate the kill ring and yank the new top \' a literal single-quote character
newline, ASCII code 10
Stopping Octave Command Completion and History \n
\t horizontal tab, ASCII code 9
quit or exit exit Octave TAB complete a command or variable name
INTERRUPT (e.g. C-c) terminate current command M-? list possible completions
enter the current line
Index Expressions
and return to top-level prompt RET var (idx) select elements of a vector
C-p move `up' through the history list var (idx1, idx2) select elements of a matrix
Getting Help C-n
M-<
move `down' through the history list
move to the rst line in the history scalar select row (column) corresponding to
scalar
help list all commands and built-in variables M-> move to the last line in the history vector select rows (columns) corresponding to the
help command brie y describe command C-r search backward in the history list elements of vector
help -i use Info to browse Octave manual C-s search forward in the history list range select rows (columns) corresponding to the
help -i command search for command in Octave manual history [-q] [N ] list N previous history lines, omitting elements of range
history numbers if -q select all rows (columns)
Motion in Info history -w [ le] write history to le ( /.octave hist if no
:

SPC
DEL
or C-v
or M-v
scroll forward one screenful
scroll backward one screenful le argument) Global Variables
C-l redraw the display history -r [ le] read history from le ( /.octave hist if global var1 ... Declare variables global.
no le argument) Global variables may be accessed inside the body of a
Node Selection in Info edit history lines edit and then run previous commands function without having to be passed in the function
from the history list parameter list provided they are also declared global within
n select the next node run history lines run previous commands from the history the function.
p select the previous node list
u
t
select the `up' node
select the `top' node [beg ] [end ] Specify the rst and last history Selected Built-in Variables
d select the directory node commands to edit or run. EDITOR editor to use with edit history
< select the rst node in the current le If beg is greater than end, reverse the list of commands Inf, NaN IEEE in nity, NaN
> select the last node in the current le before editing. If end is omitted, select commands from LOADPATH path to search for function les
g reads the name of a node and selects it beg to the end of the history list. If both arguments are PAGER program to use to paginate output
C-x k kills the current node omitted, edit the previous item in the history list. ans last result not explicitly assigned
eps machine precision
Searching in Info Shell Commands pi 
cd dir change working directory to dir realmax maximum representable value
s search for a string pwd print working directory realmin minimum representable value
C-s search forward incrementally
C-r search backward incrementally ls [ options] print directory listing automatic replot automatically redraw plots
i search index & go to corresponding node getenv ( string) return value of named environment do fortran indexing Fortran-style indexing of matrices
, go to next match from last `i' command variable implicit str to num ok allow strings to become numbers
shell cmd ( cmd) execute arbitrary shell command string output max field width maximum numeric eld width
Command-Line Cursor Motion output precision min signi cant gures displayed
C-b move back one character Matrices page screen output control whether output is paged
create column vectors by default
C-f move forward one character Square brackets delimit literal matrices. Commas separate prefer column vectors
C-a move the the start of the line elements on the same row. Semicolons separate rows. Commas resize on range error automatic resizing of matrices
C-e move to the end of the line may be replaced by spaces, and semicolons may be replaced by save precision digits stored by save command
M-f move forward a word one or more newlines. Elements of a matrix may be arbitrary silent functions suppress output from functions
M-b move backward a word expressions, provided that all the dimensions agree. warn divide by zero suppress divide by zero errors
C-l clear screen, reprinting current line at top [ x, y, ... ] enter a row vector commas in literal matrix
[ x; y; ... ] enter a column vector control handling of spaces in matrices
Inserting or Changing Text [ w, x; y, z ] enter a 22 matrix ignore function time stamp
M-TAB insert a tab character ignore changes in function les during session
DEL delete character to the left of the cursor Ranges
C-d delete character under the cursor base : limit ok to lose imaginary part
C-v add the next character verbatim base : incr : limit allow complex to real conversion
C-t transpose characters at the point Specify a range of values beginning with base with no prefer zero one indexing
M-t transpose words at the point elements greater than limit. If it is omitted, the default if ambiguous, prefer 0-1 style indexing
value of incr is 1. Negative increments are permitted.
[ ] surround optional arguments ... show one or more arguments
Copyright 1994, John W. Eaton Permissions on back
Arithmetic and Increment Operators Statements Linear Algebra
x+y addition for identi er = expr stmt-list endfor a
chol ( ) Cholesky factorization
x-y subtraction Execute stmt-list once for each column of expr. The a
det ( ) compute the determinant of a matrix
x*y matrix multiplication variable identi er is set to the value of the current column a
eig ( ) eigenvalues and eigenvectors
x .* y element by element multiplication during each iteration. a
expm ( ) compute the exponential of a matrix
x/y right division, conceptually equivalent to a
hess ( ) compute Hessenberg decomposition
(inverse (y') * x')' condition) stmt-list endwhile
while ( a
inverse ( ) invert a square matrix
x ./ y element by element right division Execute stmt-list while condition is true. a p
norm ( , ) compute the p-norm of a matrix
x\y left division, conceptually equivalent to pinv ( )a compute pseudoinverse of a
inverse (x) * y break exit innermost loop a
qr ( ) compute the QR factorization of a matrix
x .\ y element by element left division continue go to beginning of innermost loop rank ( )a matrix rank
x^y power operator return return to calling function a
schur ( ) Schur decomposition of a matrix
x .^ y element by element power operator a
svd ( ) singular value decomposition
- x negation if (condition) if-body [else else-body] endif a b c
syl ( , , ) solve the Sylvester equation
+ x unary plus (a no-op)
x' complex conjugate transpose Execute if-body if condition is true, otherwise execute else-
x .' transpose body. Equations, ODEs, DAEs, Quadrature
++ x (-- x) increment (decrement) x, return new value if (condition) if-body [elseif (condition) elseif-body] endif *fsolve solve nonlinear algebraic equations
x ++ (x --) increment (decrement) x, return old value Execute if-body if condition is true, otherwise execute the *lsode integrate nonlinear ODEs
elseif-body corresponding to the rst elseif condition that *dassl integrate nonlinear DAEs
Assignment Expressions is true, otherwise execute else-body.
Any number of elseif clauses may appear in an if
*quad integrate nonlinear functions
var = expr assign expression to variable statement. perror ( nm, code) for functions that return numeric codes,
var (idx) = expr assign expression to indexed variable print error message for named function
unwind protect body unwind protect cleanup cleanup end and given error code
Comparison and Boolean Operators Execute body. Execute cleanup no matter how control exits * See the on-line or printed manual for the complete list of
These operators work on an element-by-element basis. Both body. arguments for these functions.
arguments are always evaluated.
x<y true if x is less than y De ning Functions Signal Processing
x <= y true if x is less than or equal to y fft ( ) a Fast Fourier Transform using FFTPACK
x == y true if x is greater than y function ret-list] function-name [ (arg-list) ]
[ ifft ( ) a inverse FFT using FFTPACK
x >= y true if x is greater than or equal to y function-body freqz ( args) FIR lter frequency response
x>y true if x is equal to y endfunction sinc ( ) x returns sin ( x)/( x)
x != y true if x is not equal to y
x&y
x|y
true if both x and y are true
true if at least one of x or y is true
ret-list may be a single identi er or a comma-separated list of
identi ers delimited by square-brackets.
Image Processing
! bool true bool is false colormap ( ) map set the current colormap
arg-list is a comma-separated list of identi ers and may be gray2ind ( , ) i n convert gray scale to Octave image
empty.
Short-circuit Boolean Operators image ( , img zoom
)
img zoom
display an Octave image matrix
display scaled matrix as image
Operators evaluate left-to-right, expecting scalar operands.
Operands are only evaluated if necessary, stopping once overall
Basic Matrix Manipulations imagesc (
imshow ( ,
, )
img map
) display Octave image
truth value can be determined. Operands are converted to rows ( )a return number of rows of a imshow ( , ) i n display gray scale image
scalars by applying the all function. columns ( ) a return number of columns of a imshow ( , , ) r g b display RGB image
all ( )a check if all elements of a nonzero ind2gray ( , img map
) convert Octave image to gray scale
x && y true if both x and y are true any ( )a check if any elements of a nonzero ind2rgb ( , img map
) convert indexed image to RGB
x || y true if at least one of x or y is true find ( ) a return indices of nonzero elements loadimage ( ) le load an image le
sort ( ) a order elements in each column of a r g b
Operator Precedence sum ( )a sum elements in columns of a rgb2ind ( , , ) convert RGB to Octave image
le img fmt, map) save a matrix to le
Here is a table of the operators in Octave, in order of prod ( ) a product of elements in columns of a saveimage ( , ,

increasing precedence. min ( args


) nd minimum values Sets
statement separators max ( args
) nd maximum values
; ,
x y
rem ( , ) nd remainder of x/y create set ( , ) a b create row vector of unique values
= assignment, groups left to right reshape ( , a m, n) reformat a to be m by n complement ( , ) a b elements of b not in a
|| && logical \or" and \and" intersection ( , ) a b intersection of sets a and b
| & element-wise \or" and \and" v k
diag ( , ) create diagonal matrices union ( , ) a b union of sets a and b
< <= == >= > != relational operators
colon b l n) create vector of linearly-spaced elements
:
+ - addition and subtraction
linspace ( , ,
b l n) create vector of log-spaced elements
logspace ( , , Strings
* / \ .* ./ .\ multiplication and division n m
eye ( , ) create n by m identity matrix strcmp ( , ) s t compare strings
' .' transpose n m
ones ( , ) create n by m matrix of ones strcat ( , , ...)s t concatenate strings
+ - ++ -- ! unary minus, increment, logical \not" n m
zeros ( , ) create n by m matrix of zeros
^ .^ exponentiation n m
rand ( , ) create n by m matrix of random values
C-style Input and Output Basic Plotting
fopen ( name mode
, ) open le name gplot [ranges] expr [using] [title] [style] 2D plotting
fclose ( le
) close le
printf ( fmt, ...) formatted output to stdout gsplot [ranges] expr [using] [title] [style] 3D plotting
fprintf ( le fmt
, , ...) formatted output to le ranges specify data ranges
sprintf ( fmt, ...) formatted output to string expr expression to plot
scanf ( fmt
) formatted input from stdin using specify columns to plot
fscanf ( le fmt
, ) formatted input from le title specify line title for legend
sscanf ( ,str fmt ) formatted input from string style specify line style
fgets ( le len
, ) read len characters from le If ranges are supplied, they must come before the expression
fflush ( le
) ush pending output to le to plot. The using , title , and style options may appear in any
ftell ( le
) return le pointer position order after expr . Multiple expressions may be plotted with a
frewind ( le) move le pointer to beginning single command by separating them with commas.
freport print a info for open les set options set plotting options
fread ( le size prec
, , ) read binary data les show options show plotting options
fwrite ( le size prec write binary data les
, , ) replot redisplay current plot
feof ( le
) determine if pointer is at EOF closeplot close stream to gnuplot process
A le may be referenced either by name or by the number purge tmp files clean up temporary plotting les
returned from fopen. Three les are preconnected when automatic replot built-in variable
Octave starts: stdin, stdout, and stderr.
Other Plotting Functions
Other Input and Output functions plot ( args
) 2D plot with linear axes
save le var ... save variables in le semilogx ( args
) 2D plot with logarithmic x-axis
load le load variables from le semilogy ( args
) 2D plot with logarithmic y-axis
disp (var) display value of var to screen loglog ( args
) 2D plot with logarithmic axes
args plot bar charts
Miscellaneous Functions bar ( )
x y
stairs ( , ) plot stairsteps
str
eval ( ) evaluate str as a command y x
hist ( , ) plot histograms
str
feval ( , ...) evaluate function named by str, passing
remaining args to called function title ( string) set plot title
error ( message) print message and return to top level axis ( limits) set axis ranges
pattern clear variables matching pattern xlabel ( string) set x-axis label
clear
str) check existence of variable or function ylabel ( string) set y-axis label
[onjo ]
exist (
who list current variables grid set grid state
[onjo ] set hold state
Polynomials hold
ishold return 1 if hold is on, 0 otherwise
p
compan ( ) companion matrix
a b
conv ( , ) convolution x y z
mesh ( , , ) plot 3D surface
a b
deconv ( , ) deconvolve two vectors x y
meshdom ( , ) create mesh coordinate matrices
a
poly ( ) create polynomial from a matrix
p
polyderiv ( ) derivative of polynomial
polyreduce ( ) p integral of polynomial
polyval ( , ) p x value of polynomial at x
polyvalm ( , ) p x value of polynomial at x
roots ( ) p polynomial roots Edition 1.1 for Octave Version 1.1.0. Copyright 1994, 1995,
residue ( , ) a b partial fraction expansion of ratio a/b John W. Eaton (jwe@che.utexas.edu). The author assumes no
responsibility for any errors on this card.
Statistics
corrcoef ( , x y) correlation coecient This card may be freely distributed under the terms of the GNU
x y
cov ( , ) covariance General Public License.
a
mean ( ) mean value TEX Macros for this card by Roland Pesch (pesch@cygnus.com),
a
median ( ) median value originally for the GDB reference card
a
std ( ) standard deviation
a
var ( ) variance Octave itself is free software; you are welcome to distribute copies
of it under the terms of the GNU General Public License. There is
absolutely no warranty for Octave.

You might also like