<<

Octave Quick Reference Version 3.0.0 Killing and Yanking shiftdim (arr, s) rotate the array dimensions. -k to the end of the line circshift (arr, s) rotate the array elements. Starting Octave C-y yank the recently killed text octave start interactive Octave session M- kill to the end of the current word Sparse Matrices octave file run Octave on commands in file M-DEL kill the word behind the cursor sparse (...) create sparse matrix. octave --eval code Evaluate code using Octave M-y rotate the kill ring and yank the new speye (n) create sparse identify matrix. octave -- describe command line options sprand (n, m, d) sparse rand matrix of density d. Command Completion and spdiags (...) sparse generalization of diag. Stopping Octave TAB complete a command or variable name nnz (s) No. non-zero elements in sparse matrix. quit or exit Octave M-? list possible completions INTERRUPT (.. C-c) terminate current command and RET enter the current line Ranges return to top-level prompt C-p move ‘up’ through the history list base : limit C-n move ‘down’ through the history list base : incr : limit Getting Help M-< move to the first line in the history Specify a range of values beginning with base with no help list all commands and built-in variables M-> move to the last line in the history elements greater than limit. If it is omitted, the default help command briefly describe command C-r search backward in the history list value of incr is 1. Negative increments are permitted. doc use to browse Octave manual C-s search forward in the history list doc command search for command in Octave manual history [-q][N ] list N previous history lines, omitting Strings and Common Escape Sequences lookfor str search for command based on str history numbers if -q A string constant consists of a sequence of characters enclosed history - [file] history to file (~/.octave hist if no in either double-quote or single-quote marks. Strings in double- Motion in Info file argument) quotes allow the use of the escape sequences below. SPC or C-v scroll forward one screenful history -r [file] read history from file (~/.octave hist if \\ a literal backslash DEL or M-v scroll backward one screenful no file argument) \" a literal double-quote character C-l redraw the display edit history lines edit and then run previous commands \’ a literal single-quote character from the history list \n newline, ASCII code 10 Node Selection in Info run history lines run previous commands from the history \t horizontal tab, ASCII code 9 n select the next node list p select the previous node [beg][end] Specify the first and last history Index Expressions u select the ‘up’ node commands to edit or run. var (idx) select elements of a vector t select the ‘top’ node If beg is greater than end, reverse the list of commands var (idx1, idx2) select elements of a matrix d select the directory node before editing. If end is omitted, select commands from scalar select row (column) corresponding to < select the first node in the current file beg to the end of the history list. If both arguments are scalar > select the last node in the current file omitted, edit the previous item in the history list. vector select rows (columns) corresponding to the g reads the name of a node and selects it elements of vector C-x k kills the current node Shell Commands range select rows (columns) corresponding to the dir change working directory to dir elements of range Searching in Info print working directory : select all rows (columns) s search for a string [options] print directory listing Global and Persistent Variables C-s search forward incrementally getenv (string) return value of named environment C-r search backward incrementally variable global var1 ... Declare variables global. i search index & go to corresponding node system (cmd) execute arbitrary shell command string global var1 = val Declare variable global. Set intial value. , go to next match from last ‘i’ command persistent var1 Declare a variable as static to a function. Matrices persistent var1 = Declare a variable as static to a function Command-Line Cursor Motion Square brackets delimit literal matrices. Commas separate val and set its initial value. C- move back one character elements on the same row. Semicolons separate rows. Commas Global variables may be accessed inside the body of a function C- move forward one character may be replaced by spaces, and semicolons may be replaced by without having to be passed in the function parameter list C-a move to the start of the line one or newlines. Elements of a matrix may be arbitrary provided they are declared global when used. C-e move to the end of the line expressions, assuming all the dimensions agree. move forward a word Selected Built-in Functions M-f [ x, y, ... ] enter a row vector move backward a word EDITOR editor to use with edit history M-b [ x; y; ... ] enter a column vector C-l screen, reprinting current line top Inf, NaN IEEE infinity, NaN [ w, x; y, z ] enter a 2×2 matrix NA Missing value Inserting or Changing Text PAGER program to use to paginate output Multi-dimensional Arrays ans last result not explicitly assigned M-TAB insert a tab character Multi-dimensional arrays may be created with the or eps machine precision DEL delete character to the left of the cursor reshape commands from two-dimensional sub-matrices. pi π C-d delete character under the cursor √ C-v add the next character verbatim squeeze (arr) remove singleton dimensions of the array. 1i −1 C-t transpose characters at the point ndims (arr) number of dimensions in the array. realmax maximum representable value M-t transpose words at the point permute (arr, p) permute the dimensions of an array. realmin minimum representable value ipermute (arr, p) array inverse permutation. [] surround optional arguments ... show one or more arguments Copyright 1996, 1997, 2007 John W. Eaton Permissions on back Assignment Expressions Paths and Packages Function Handles var = assign expression to variable path display the current Octave cunction path. @func Define a function handle to func. var (idx) = expr assign expression to indexed variable pathdef display the default path. @(var1, ...) expr Define an anonymous function handle. var (idx) = [] delete the indexed elements. addpath(dir) add a directory to the path. str2func (str) Create a function handle from a string. var {idx} = expr assign elements of a cell array. EXEC PATH manipulate the Octave executable path. functions (handle) Return information about a function pkg list display installed packages. handle. Arithmetic and Increment Operators pkg load pack Load an installed package. func2str (handle) Return a string representation of a function handle. x + y addition Cells and Structures handle (arg1, ...) Evaluate a function handle. x - y subtraction feval (func, arg1, Evaluate a function handle or string, var.field = ... set a field of a structure. x * y matrix multiplication ...) passing remaining args to func x .* y element by element multiplication var{idx} = ... set an element of a cell array. Anonymous function handles take a copy of the variables in the x / y right division, conceptually equivalent to cellfun(f, c) apply a function to elements of cell array. current workspace. (inverse (y’) * x’)’ fieldnames(s) returns the fields of a structure. x ./ y element by element right division Miscellaneous Functions x \ y left division, conceptually equivalent to Statements eval (str) evaluate str as a command inverse (x) * y for identifier = expr stmt-list endfor error (message) print message and return to top level x .\ y element by element left division Execute stmt-list once for each column of expr. The variable warning (message) print a warning message x ^ y power operator identifier is set to the value of the current column during clear pattern clear variables matching pattern x .^ y element by element power operator each iteration. str check existence of variable or function - x negation exist ( ) , whos list current variables + x unary plus (a no-op) while (condition) stmt-list endwhile whos var details of the varibale var x ’ complex conjugate transpose Execute stmt-list while condition is true. x .’ transpose Basic Matrix Manipulations ++ x (-- x) increment (decrement), return new value break exit innermost loop x ++ (x --) increment (decrement), return old value continue go to beginning of innermost loop rows (a) return number of rows of a return return to calling function columns (a) return number of columns of a Comparison and Boolean Operators all (a) check if all elements of a nonzero any (a) check if any elements of a nonzero These operators work on an element-by-element basis. Both if (condition) if-body [else else-body] endif Execute if-body if condition is true, otherwise execute else- arguments are always evaluated. (a) return indices of nonzero elements body. x < y true if x is less than y sort (a) order elements in each column of a x <= y true if x is less than or equal to y if (condition) if-body [elseif (condition) elseif-body] endif (a) sum elements in columns of a x == y true if x is equal to y Execute if-body if condition is true, otherwise execute the prod (a) product of elements in columns of a x >= y true if x is greater than or equal to y elseif-body corresponding to the first elseif condition that min (args) find minimum values x > y true if x is greater than y is true, otherwise execute else-body. max (args) find maximum values x != y true if x is not equal to y Any number of elseif clauses may appear in an if rem (x, y) find remainder of x/y x & y true if both x and y are true statement. reshape (a, m, n) reformat a to be m by n x | y true if at least one of x or y is true diag (v, k) create diagonal matrices ! bool true if bool is false unwind protect body unwind protect cleanup cleanup end linspace (b, l, n) create vector of linearly-spaced elements Execute body. Execute cleanup no matter how control exits logspace (b, l, n) create vector of log-spaced elements Short-circuit Boolean Operators body. eye (n, m) create n by m identity matrix try body catch cleanup end Operators evaluate left-to-right. Operands are only evaluated if ones (n, m) create n by m matrix of ones Execute body. Execute cleanup if body fails. necessary, stopping once overall truth value can be determined. zeros (n, m) create n by m matrix of zeros Operands are converted to scalars using the all function. rand (n, m) create n by m matrix of random values Strings x && y true if both x and y are true strcmp (s, t) compare strings Linear Algebra x || y true if at least one of x or y is true strcat (s, t, ...) concatenate strings chol (a) Cholesky factorization Operator Precedence regexp (str, pat) strings matching regular expression det (a) compute the determinant of a matrix regexprep (str, pat, rep) Match and replace sub-strings eig (a) eigenvalues and eigenvectors Table of Octave operators, in order of increasing precedence. expm (a) compute the exponential of a matrix ;, statement separators Defining Functions hess (a) compute Hessenberg decomposition = assignment, groups left to right inverse (a) invert a square matrix function [ret-list] function-name [ (arg-list) ] || && logical “or” and “and” norm (a, p) compute the p-norm of a matrix | & element-wise “or” and “and” function-body pinv (a) compute pseudoinverse of a < <= == >= > != relational operators endfunction qr (a) compute the QR factorization of a matrix : colon rank (a) matrix rank ret-list may be a single identifier or a comma-separated list of + - addition and subtraction sprank (a) structrual matrix rank identifiers delimited by square-brackets. * / \ .* ./ .\ multiplication and division schur (a) Schur decomposition of a matrix ’ .’ transpose arg-list is a comma-separated list of identifiers and may be svd (a) singular value decomposition + - ++ -- ! unary minus, increment, logical “not” empty. syl (a, b, c) solve the Sylvester equation ^ .^ exponentiation Equations, ODEs, DAEs, Quadrature Polynomials *fsolve solve nonlinear algebraic equations compan (p) companion matrix *lsode integrate nonlinear ODEs conv (a, b) convolution *dassl integrate nonlinear DAEs deconv (a, b) deconvolve two vectors *quad integrate nonlinear functions poly (a) create polynomial from a matrix perror (, code) for functions that return numeric codes, polyderiv (p) derivative of polynomial print error message for named function polyreduce (p) integral of polynomial and given error code polyval (p, x) value of polynomial at x * See the on-line or printed manual for the complete list of polyvalm (p, x) value of polynomial at x arguments for these functions. roots (p) polynomial roots residue (a, b) partial fraction expansion of ratio a/b Signal Processing fft (a) Fast Fourier Transform using FFTW Statistics ifft (a) inverse FFT using FFTW corrcoef (x, y) correlation coefficient freqz (args) FIR filter response cov (x, y) covariance (a, b, x) filter by transfer function mean (a) mean value conv (a, b) convolve two vectors median (a) median value hamming (n) return Hamming window coefficents std (a) standard deviation hanning (n) return Hanning window coefficents var (a) variance Image Processing Plotting Functions colormap (map) set the current colormap plot (args) 2D plot with linear axes gray2ind (i, n) convert gray scale to Octave image plot3 (args) 3D plot with linear axes image (img, zoom) display an Octave image matrix line (args) 2D or 3D line imagesc (img, zoom) display scaled matrix as image (args) 2D patch imshow (img, map) display Octave image semilogx (args) 2D plot with logarithmic x-axis imshow (i, n) display gray scale image semilogy (args) 2D plot with logarithmic y-axis imshow (r, g, b) display RGB image loglog (args) 2D plot with logarithmic axes ind2gray (img, map) convert Octave image to gray scale bar (args) plot bar charts ind2rgb (img, map) convert indexed image to RGB stairs (x, y) plot stairsteps loadimage (file) load an image file stem (x, it y) plot a stem rgb2ind (r, g, b) convert RGB to Octave image hist (y, x) plot histograms saveimage (file, img, fmt, map) save a matrix to file contour (x, y, z) contour plot title (string) set plot title C-style Input and Output axis (limits) set axis ranges fopen (name, mode) open file name xlabel (string) set x-axis label fclose (file) close file ylabel (string) set y-axis label (fmt, ...) formatted output to stdout zlabel (string) set z-axis label fprintf (file, fmt, ...) formatted output to file text (x, y, str) add text to a plot sprintf (fmt, ...) formatted output to string legend (string) set label in plot key scanf (fmt) formatted input from stdin grid [on|off] set grid state fscanf (file, fmt) formatted input from file hold [on|off] set hold state sscanf (str, fmt) formatted input from string ishold return 1 if hold is on, 0 otherwise fgets (file, len) read len characters from file mesh (x, y, z) plot 3D surface fflush (file) flush pending output to file meshgrid (x, y) create mesh coordinate matrices ftell (file) return file pointer position frewind (file) move file pointer to beginning freport print a info for open files fread (file, size, prec) read binary data files Edition 2.0 for Octave Version 3.0.0. Copyright 1996, 2007, John fwrite (file, size, prec) write binary data files W. Eaton ([email protected]). The author assumes no responsibility feof (file) determine if pointer is at EOF for any errors on this card. A file may be referenced either by name or by the number returned from fopen. Three files are preconnected when Octave This card may be freely distributed under the terms of the GNU starts: stdin, stdout, and stderr. General Public License.

TEX Macros for this card by Roland Pesch ([email protected]), Other Input and Output functions originally for the GDB reference card save file var ... save variables in file load file load variables from file Octave itself is free software; you are welcome to distribute copies disp (var) display value of var to screen of it under the terms of the GNU General Public License. There is absolutely no warranty for Octave.