0% found this document useful (0 votes)
7 views2 pages

Octave 8.0.0 Quick Reference Guide

This document is a quick reference guide for Octave 8.0.0, detailing commands, functions, and operators for programming in Octave. It covers various topics such as starting and stopping Octave, matrix operations, data types, control structures, and plotting functions. The guide is intended for users to quickly access essential information and commands while working with Octave.

Uploaded by

tefiprivs
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Octave 8.0.0 Quick Reference Guide

This document is a quick reference guide for Octave 8.0.0, detailing commands, functions, and operators for programming in Octave. It covers various topics such as starting and stopping Octave, matrix operations, data types, control structures, and plotting functions. The guide is intended for users to quickly access essential information and commands while working with Octave.

Uploaded by

tefiprivs
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Octave Quick Reference Octave 8.0.0 any true if at least one element nonzero var{idx} = ...

rue if at least one element nonzero var{idx} = ... set an element of a cell array
Copyright 1996-2022 The Octave Project Developers nnz number of nonzero elements cellfun (f, c) apply a function to elements of cell array
[Link] = ... set a field of a structure
Starting and Stopping Multi-dimensional Arrays fieldnames (s) returns the fields of a structure
octave [--gui] start Octave CLI/GUI session ndims number of dimensions structfun (f, s) apply a function to fields of structure
octave file run Octave commands in file reshape squeeze change array shape classdef define new classes for OOP
octave --eval code evaluate code using Octave resize change array shape, lossy
octave --help describe command line options cat join arrays along a given dimension Assignment Expressions
quit or exit exit Octave permute ipermute like N-dimensional transpose var = expr assign value to variable
Ctrl-C terminate current command and shiftdim var(idx) = expr only the indexed elements are changed
return to top-level prompt circshift cyclically shift array elements var(idx) = [] delete the indexed elements
meshgrid matrices useful for vectorization
Getting Help Arithmetic Operators
help command briefly describe command
Ranges If two operands are of different sizes, scalars and singleton
Create sequences of real numbers as row vectors. dimensions are automatically expanded. Non-singleton
doc use Info to browse Octave manual
doc command search for command in Octave manual base : limit dimensions need to match.
lookfor str search for command based on str base : incr : limit x + y, x - y addition, subtraction
incr == 1 if not specified. Negative ranges allowed. x * y matrix multiplication
Command Completion and History x .* y element-by-element multiplication
TAB complete a command or variable name Numeric Types and Values x / y right division, conceptually equivalent to
Alt-? list possible completions Integers saturate in Octave. They do not roll over. (inverse (y’) * x’)’
Ctrl-r Ctrl-s search command history x ./ y element-by-element right division
int8 int16 int32 int64 signed integers
uint8 uint16 uint32 unsigned integers x \ y left division, conceptually equivalent to
Directory and Path Commands uint64 inverse (x) * y
cd dir change working directory to dir single double 32-bit/64-bit IEEE floating point x .\ y element-by-element left division
pwd print working directory intmin intmax flintmax integer limits of given type x ^ y power operator
ls [options] print directory listing realmin realmax floating point limits of given type x .^ y element-by-element power operator
what list .m/.mat files in the current directory inf nan NA IEEE infinity, NaN, missing value += -= *= .*= /= in-place equivalents of the above operators
path search path for Octave functions eps machine precision ./= \= .\= ^= .^=
pi e 3.14159..., 2.71828... -x negation
pathdef default search path √ +x unary plus (a no-op)
addpath (dir) add a directory to the path i j −1 0
getenv (var) value of environment variable x complex conjugate transpose
0
Strings x. transpose
Package Management A string constant consists of a sequence of characters enclosed
++x --x increment / decrement, return new value
Add-on packages are independent of core Octave, listed at x++ x-- increment / decrement, return old value
in either double-quote or single-quote marks. Strings in double-
[Link] quotes allow the use of the escape sequences below.
pkg install -forge pkg download and install pkg
Comparison and Boolean Operators
\\ a literal backslash
pkg install [Link] install pre-downloaded package file These operators work on an element-by-element basis. Both
\" a literal double-quote character
pkg list show installed packages arguments are always evaluated.
\’ a literal single-quote character
pkg load / pkg unload load/unload installed package \n newline, ASCII code 10 < <= == >= > relational operators
statistics optimization various common packages \t horizontal tab, ASCII code 9 != ~= not equal to
control signal image sprintf sscanf formatted IO to/from string & logical AND
symbolic etc. strcmp compare strings | logical OR
strcat join strings ! ~ logical NOT
Matrices strfind regexp find matching patterns
Square brackets delimit literal matrices. Commas separate strrep regexprep find and replace patterns Short-circuit Boolean Operators
elements on the same row. Semicolons separate rows. Commas
Operators evaluate left-to-right. Operands are only evaluated if
may be replaced by spaces, and semicolons may be replaced by Index Expressions necessary, stopping once overall truth value can be determined.
newlines. Elements of a matrix may be arbitrary expressions,
var(idx) select elements of a vector Non-scalar operands are converted to scalars with all.
assuming all the dimensions agree.
var(idx1, idx2) select elements of a matrix
x && y logical AND
[ x, y, ... ] enter a row vector var([1 3], :) rows 1 and 3
x || y logical OR
[ x; y; ... ] enter a column vector var(:, [2 end]) the second and last columns
[ w, x; y, z ] enter a 2×2 matrix var(1:2:end, get odd rows and even columns
rows columns number of rows/columns of matrix 2:2:end)
zeros ones create matrix of zeros/ones var1(var2 == 0) elements of var1 corresponding to zero
eye diag create identity/diagonal matrix elements of var2
rand randi randn create matrix of random values var(:) all elements as a column vector
sparse spalloc create a sparse matrix
all true if all elements nonzero Cells, Structures, and Classdefs
Operator Precedence f (args) Evaluate a function handle f rank matrix rank
Table of Octave operators, in order of decreasing precedence. feval Evaluate a function handle or string qr QR factorization
eval (str) evaluate str as a command chol Cholesky factorization
() {} . array index, cell index, structure index system (cmd) execute arbitrary shell command string svd singular value decomposition
’ .’ ^ .^ transpose and exponentiation
+ - ++ -- ! unary minus, increment, logical “not” Anonymous function handles make a copy of the variables in fsolve solve nonlinear algebraic equations
* / \ .* ./ .\ multiplication and division the current workspace at the time of creation. lsode ode45 integrate nonlinear ODEs
+ - addition and subtraction dassl integrate nonlinear DAEs
: colon
< <= == >= > != relational operators
Global and Persistent Variables integral integrate nonlinear functions

& | element-wise “and” and “or” global var = ... declare & initialize global variable
persistent var = ... persistent/static variable union set union
&& || logical “and” and “or” intersection set intersection
= += -= *= /= etc. assignment, groups left to right Global variables may be accessed inside the body of a function
without having to be passed in the function parameter list
setdiff set difference
; , statement separators
provided that they are declared global when used.
roots polynomial roots
General programming poly matrix characteristic polynomial
endfor, endwhile, endif etc. can all be replaced by end.
Common Functions
polyder polyint polynomial derivative or integral
disp display value of variable
for x = 1:10 for loop polyfit polyval polynomial fitting and evaluation
printf formatted output to stdout
endfor residue partial fraction expansion
input scanf input from stdin
legendre bessel special functions
while (x <= 10) while loop who whos list current variables
endwhile clear pattern clear variables matching pattern
conv conv2 convolution, polynomial multiplication
do do-until loop exist check existence of identifier
deconv deconvolution, polynomial division
until (x > 10) find return indices of nonzero elements
sort return a sorted array
if (x < 5) if-then-else fft fft2 ifft(a) FFT / inverse FFT
unique discard duplicate elements
elseif (x < 6) freqz FIR filter frequency response
sortrows sort whole rows in numerical or
else filter filter by transfer function
lexicographic order
endif sum prod sum or product
switch (tf) switch-case mod rem remainder functions Plotting and Graphics
case "true" min max range mean basic statistics plot plot3 2D / 3D plot with linear axes
case "false" median std line 2D or 3D line
otherwise patch fill 2D patch, optionally colored
endswitch Error Handling, Debugging, Profiling semilogx semilogy loglog logarithmic axes
break exit innermost loop error (message) print message and return to top level bar hist bar chart, histogram
warning (message) print a warning message stairs stem stairsteps and stem graphs
continue go to start of innermost loop debug guide to all debugging commands contour contour plot
profile start/stop/clear/resume profiling mesh trimesh surf plot 3D surfaces
return jump back from function to caller profshow show the results of profiling
profexplore figure new figure
try cleanup only on exception hold on add to existing figure
title set plot title
catch File I/O, Loading, Saving axis set axis range and aspect
unwind_protect cleanup always save load save/load variables to/from file
xlabel ylabel zlabel set axis labels
unwind_protect_cleanup save -binary save in binary format (faster)
text add text to a plot
dlmread dlmwrite read/write delimited data
grid legend draw grid or legend
Functions csvread csvwrite read/write CSV files
function [ret-list =] function-name [ (arg-list) ] xlsread xlswrite read/write XLS spreadsheets
image imagesc spy display matrix as image
function-body imwrite saveas print save figure or image
fopen fclose open/close files
imread load an image
endfunction fprintf fscanf formatted file I/O
colormap get or set colormap
textscan
ret-list may be a single identifier or a comma-separated list of fflush flush pending output
identifiers enclosed by square brackets.
arg-list is a comma-separated list of identifiers and may be Math Functions Quick reference for Octave 8.0.0. Copyright 1996-2022 The Octave
empty. Run doc <function> to find related functions. Project Developers. The authors assume no responsibility for any
cov corrcoef covariance, correlation coefficient errors on this card. This card may be freely distributed under the
Function Handles and Evaluation tan tanh atan2 trig and hyperbolic functions terms of the GNU General Public License.
@func create a function handle to func cross curl del2 vector algebra functions
@(vars) expr define an anonymous function Octave license and copyright: [Link]
str2func func2str convert function to/from string det inv determinant matrix inverse TEX Macros for this card by Roland Pesch (pesch@[Link]),
functions (handle) Return information about a function eig eigenvalues and eigenvectors originally for the GDB reference card
handle norm vector norm, matrix norm

You might also like