Command and Function: Quick Reference - Essential MATLAB for Engineers and Scientists (2013)

Essential MATLAB for Engineers and Scientists (2013)

APPENDIX C

Command and Function: Quick Reference

This appendix lists most of the MATLAB commands and functions used in the text, along with a few others. For a complete list by category (with links to detailed descriptions) see MATLAB: Reference: MATLAB Function Reference: Functions by Category in the online documentation.

The command help by itself displays a list of all the function categories (each in its own directory).

C.1. General-purpose commands

demo

Run demos

help

Online help

helpwin

Display categories of functions with links to each category

lookfor

Keyword search through help entries

type

List M-files

what

Directory listing of M- and MAT-files

which

Locate functions and files

C.1.1. Managing variables and the workspace

clear

Clear variables and functions from memory

disp

Display matrix or text

length

Length of vector

load

Retrieve variables from disk

save

Save workspace variables to disk

size

Array dimensions

who, whos

List variables in workspace

C.1.2. Files and the operating system

beep

Produce beep sound

cd

Change current working directory

delete

Delete file

diary

Save text of MATLAB session

dir

Directory listing

edit

Edit M-file

!

Execute operating system command

C.1.3. Controlling the Command Window

clc

Clear Command Window

echo

Echo commands in script

format

Set output format for disp

home

Send cursor home

more

Control paged output

C.1.4. Starting and quitting MATLAB

exit

Terminate MATLAB

quit

Terminate MATLAB

startup

Execute M-file when MATLAB starts

C.2. Logical functions

all

True if all elements of vector are true (nonzero)

any

True if any element of vector is true

exist

Check if variable or file exists

find

Find indices of nonzero elements

is*

Detect various states

logical

Convert numeric values to logical values

C.3. MATLAB programming tools

error

Display error message

eval

Interpret string containing MATLAB expression

feval

Function evaluation

for

Repeat statement specific number of times

global

Define global variable

if

Conditionally execute statements

persistent

Define persistent variable

switch

Switch among several cases

try

Begin try block

while

Repeat statements conditionally

C.3.1. Interactive input

input

Prompt user for input

keyboard

Invoke keyboard as script file

menu

Generate menu of choices for user input

pause

Wait for user response

C.4. Matrices

eye

Identity matrix

linspace

Vector with linearly spaced elements

ones

Matrix of ones

rand

Uniformly distributed random numbers and arrays

randn

Normally distributed random numbers and arrays

zeros

Matrix of zeros

: (colon)

Vector with regularly spaced elements

C.4.1. Special variables and constants

ans

Most recent answer

eps

Floating-point relative accuracy

i or j

Image

Inf

Infinity

NaN

Not-a-Number

nargin, nargout

Number of actual function arguments

pi

3.14159 26535 897 …

realmax

Largest positive floating-point number

realmin

Smallest positive floating-point number

varargin, varargout

Pass or return variable numbers of arguments

C.4.2. Time and date

calendar

Calendar

clock

Wall clock (complete date and time)

date

Actual date

etime

Elapsed time

tic, toc

Stopwatch

weekday

Day of week

C.4.3. Matrix manipulation

cat

Concatenate arrays

diag

Create or extract diagonal

fliplr

Flip in left/right direction

flipud

Flip in up/down direction

repmat

Replicate and tile array

reshape

Change shape

rot90

Rotate 90

tril

Extract lower tridiagonal part

triu

Extract upper tridiagonal part

C.4.4. Specialized matrices

gallery

Test matrices

hilb

Hilbert matrix

magic

Magic square

pascal

Pascal matrix

wilkinson

Wilkinson's eigenvalue test matrix

C.5. Mathematical functions

abs

Absolute value

acos, acosh

Inverse cosine, inverse hyperbolic cosine

acot, acoth

Inverse cotangent, inverse hyperbolic cotangent

acsc, acsch

Inverse cosecant, and inverse hyperbolic cosecant

angle

Phase angle

asec, asech

Inverse secant, inverse hyperbolic secant

asin, asinh

Inverse sine, inverse hyperbolic sine

atan, atanh

Inverse tangent (two quadrant), inverse hyperbolic tangent

atan2

Inverse tangent (four quadrant)

bessel

Bessel function

ceil

Round up

conj

Complex conjugate

cos, cosh

Cosine, hyperbolic cosine

cot, coth

Cotangent, hyperbolic cotangent

csc, csch

Cosecant, hyperbolic cosecant

erf

Error function

exp

Exponential

fix

Round toward zero

floor

Round down

gamma

Gamma function

imag

Imaginary part

log

Natural logarithm

log2

Dissect floating-point numbers into exponent and mantissa

log10

Common logarithm

mod

Modulus (signed remainder after division)

rat

Rational approximation

real

Real part

rem

Remainder after division

round

Round toward nearest integer

sec, sech

Secant, hyperbolic secant

sign

Signum function

sin, sinh

Sine, hyperbolic sine

sqrt

Square root

tan, tanh

Tangent, hyperbolic tangent

C.6. Matrix functions

det

Determinant

eig

Eigenvalues and eigenvectors

expm

Matrix exponential

inv

Matrix inverse

poly

Characteristic polynomial

rank

Number of linearly independent rows or columns

rcond

Condition estimator

trace

Sum of diagonal elements

{}\ and /

Linear equation solution

C.7. Data analysis

cumprod

Cumulative product

cumsum

Cumulative sum

diff

Difference function

fft

One-dimensional fast Fourier transform

max

Largest element

mean

Average value of elements

median

Median value of elements

min

Smallest element

prod

Product of elements

sort

Sort in ascending order

std

Standard deviation

sum

Sum of elements

trapz

Trapezoidal rule for numerical integration

C.8. Polynomial functions

polyfit

Fit polynomial to data

polyval

Evaluate polynomial

roots

Find polynomial roots

C.9. Function functions

bvp4c

Solve two-point boundary value problems for ODEs

fmin

Minimize function of one variable

fmins

Minimize function of several variables

fzero

Find zero of function of one variable

ode23, ode23s,

ode45

Solve initial value problems for ODEs

quad

Numerical integration

C.10. Sparse matrix functions

full

Convert sparse matrix to full matrix

sparse

Construct sparse matrix from nonzeros and subscripts

spy

Visualize sparse matrix

C.11. Character string functions

char

characters from ASCII codes

double

ASCII codes of characters

lower

Convert string to lower case

sprintf

Write formatted data to string

str2mat

String-to-matrix conversion

strcat

String concatenation

strcmp

Compare strings

upper

Convert string to upper case

C.12. File I/O functions

fclose

Close one or more open files

feof

Test for end-of-file

fopen

Open file or obtain information about open files

fprintf

Write formatted data to file

fread

Read binary data from file

fscanf

Read formatted data from file

fseek

Set file position indicator

ftell

Get file position indicator

fwrite

Write binary data to file

C.13. 2D graphics

bar

Bar graph

grid

Grid lines

hist

Histogram plot

loglog

Log-log scale plot

plot

Linear plot

polar

Polar coordinate plot

semilogx

Semi-log scale plot

semilogy

Semi-log scale plot

text

Text annotation

title

Graph title

xlabel

x-axis label

ylabel

y-axis label

zoom

Zoom in and out on 2D plot

C.14. 3D graphics

clabel

Contour plot elevation label

comet3

Animated 3D plot

contour

Contour plot in 2D

contour3

Contour plot in 3D

mesh

3D mesh surface

meshc

3D mesh surface with contour plot

meshgrid

X and Y arrays for 3D plots

plot3

Line plot in 3D

quiver

Quiver plot

surf

Shaded surface

surfl

Shaded surface with lighting

view

Rotation of 3D figure

zlabel

z-axis label

C.15. General

axes

Create axes object

axis

Control axis scaling and appearance

cla

Clear axes

clf

Clear current figure

colorbar

Display color bar (color scale)

colormap

Set color look-up table (list of colormaps)

drawnow

Complete any pending drawing

figure

Create figure (graph) windows

fplot

Plot function

gca

Get current axes handle

gcf

Get current figure handle

gco

Return handle of current graphics object

get

Get graphics object properties

ginput

Graphical input from mouse or cursor

gtext

Mouse placement of text

set

Set graphics object properties

subplot

Create axes in tiled positions