SlideShare uma empresa Scribd logo
1 de 17
Baixar para ler offline
MATLAB Commands and Functions
Dr. Brian Vick
Mechanical Engineering Department
Virginia Tech
General Purpose Commands
Operators and Special Characters / 3
Commands for Managing a Session / 3
Special Variables and Constants / 4
System and File Commands / 4

Input/Output and Formatting Commands
Input/Output Commands / 5
Format Codes for fprintf and fscanf / 5
Numeric Display Formats / 5

Vector, Matrix and Array Commands
Array Commands / 6
Special Matrices / 6
Matrix Arithmetic / 6
Matrix Commands for Solving Linear Equations / 6
Cell Array Functions / 7
Structure Functions / 7

Plotting Commands
Basic xy Plotting Commands / 8
Plot Enhancement Commands / 8
Specialized Plot Commands / 8
Colors, Symbols and Line Types / 9
Three-Dimensional Plotting Commands / 9
Histogram Functions / 9

MATLAB Commands – 1
Programming
Logical and Relational Operators / 10
Program Flow Control / 10
Logical Functions / 10
M-Files / 11
Timing /11

Mathematical Functions
Exponential and Logarithmic Functions / 12
Trigonometric Functions / 12
Hyperbolic Functions / 12
Complex Functions / 13
Statistical Functions / 13
Random Number Functions / 13
Numeric Functions / 13
String Functions / 13

Numerical Methods
Polynomial and Regression Functions / 14
Interpolation Functions / 14
Numerical Integration Functions / 14
Numerical Differentiation Functions / 14
ODE Solvers / 15
Predefined Input Functions / 15

Symbolic Math Toolbox
Functions for Creating and Evaluating Symbolic Expressions / 16
Functions for Manipulating Symbolic Expressions / 16
Symbolic Calculus Functions / 16
Symbolic Solution of Algebraic and Transcendental Equations / 17
Symbolic Solution of Differential Equations / 17
Laplace Transform Functions / 17
Symbolic Linear Algebra Functions / 17

MATLAB Commands – 2
General Purpose Commands
Operators and Special Characters
+
*
.*
^
.^

/
.
./
:
( )
[ ]
.
…
,
;
%
_
._
=

Plus; addition operator.
Minus; subtraction operator.
Scalar and matrix multiplication operator.
Array multiplication operator.
Scalar and matrix exponentiation operator.
Array exponentiation operator.
Left-division operator.
Right-division operator.
Array left-division operator.
Array right-division operator.
Colon; generates regularly spaced elements and represents an entire row or column.
Parentheses; encloses function arguments and array indices; overrides precedence.
Brackets; enclosures array elements.
Decimal point.
Ellipsis; line-continuation operator.
Comma; separates statements and elements in a row.
Semicolon; separates columns and suppresses display.
Percent sign; designates a comment and specifies formatting.
Quote sign and transpose operator.
Nonconjugated transpose operator.
Assignment (replacement) operator.

Commands for Managing a Session
clc
clear
exist
global
help
lookfor
quit
who
whos

Clears Command window.
Removes variables from memory.
Checks for existence of file or variable.
Declares variables to be global.
Searches for a help topic.
Searches help entries for a keyword.
Stops MATLAB.
Lists current variables.
Lists current variables (long display).

MATLAB Commands – 3
Special Variables and Constants
ans
eps
i,j
Inf
NaN
pi

Most recent answer.
Accuracy of floating-point precision.
The imaginary unit - 1.
Infinity.
Undefined numerical result (not a number).
The number p .

System and File Commands
cd
date
delete
diary
dir
load
path
pwd
save
type
what
wklread

Changes current directory.
Displays current date.
Deletes a file.
Switches on/off diary file recording.
Lists all files in current directory.
Loads workspace variables from a file.
Displays search path.
Displays current directory.
Saves workspace variables in a file.
Displays contents of a file.
Lists all MATLAB files in the current directory.
Reads .wk1 spreadsheet file.

MATLAB Commands – 4
Input/Output and Formatting Commands
Input/Output Commands
disp
fscanf
format
fprintf
input
;

Displays contents of an array or string.
Read formatted data from a file.
Controls screen-display format.
Performs formatted writes to screen or file.
Displays prompts and waits for input.
Suppresses screen printing.

Format Codes for fprintf and fscanf
%s
%d
%f
%e
%g
n
t

Format as a string.
Format as an integer.
Format as a floating point value.
Format as a floating point value in scientific notation.
Format in the most compact form: %f or %e.
Insert a new line in the output string.
Insert a tab in the output string.

Numeric Display Formats
format
format
format
format
format
format
format
format
format

short
long
short e
long e
bank
+
rat
compact
loose

Four decimal digits (default).
16 decimal digits.
Five digits plus exponent.
16 digits plus exponents.
Two decimal digits.
Positive, negative, or zero.
Rational approximation.
Suppresses some line feeds.
Resets to less compact display mode.

MATLAB Commands – 5
Vector, Matrix and Array Commands
Array Commands
cat
find
length
linspace
logspace
max
min
prod
reshape
size
sort
sum

Concatenates arrays.
Finds indices of nonzero elements.
Computers number of elements.
Creates regularly spaced vector.
Creates logarithmically spaced vector.
Returns largest element.
Returns smallest element.
Product of each column.
Change size
Computes array size.
Sorts each column.
Sums each column.

Special Matrices
eye
ones
zeros

Creates an identity matrix.
Creates an array of ones.
Creates an array of zeros.

Matrix Arithmetic
cross
dot

Computes cross products.
Computes dot products.

Matrix Commands for Solving Linear Equations
det
inv
pinv
rank
rref

Computes determinant of an array.
Computes inverse of a matrix.
Computes pseudoinverse of a matrix.
Computes rank of a matrix.
Computes reduced row echelon form.

MATLAB Commands – 6
Cell Array Functions
cell
celldisp
cellplot
num2cell
deal
iscell

Creates cell array.
Displays cell array.
Displays graphical representation of cell array.
Converts numeric array to cell array.
Matches input and output lists.
Identifies cell array.

Structure Functions
fieldnames
getfield
isfield
isstruct
rmfield
setfield
struct

Returns field names in a structure array.
Returns field contents of a structure array.
Identifies a structure array field.
Identifies a structure array.
Removes a field from a structure array.
Sets contents of field.
Creates structure array.

MATLAB Commands – 7
Plotting Commands
Basic xy Plotting Commands
axis
fplot
grid
plot
print
title
xlabel
ylabel

Sets axis limits.
Intelligent plotting of functions.
Displays gridlines.
Generates xy plot.
Prints plot or saves plot to a file
Puts text at top of plot.
Adds text label to x-axis.
Adds text label to y-axis.

Plot Enhancement Commands
axes
close
close all
figure
gtext
hold
legend
refresh
set
subplot
text

Creates axes objects.
Closes the current plot.
Closes all plots.
Opens a new figure window.
Enables label placement by mouse.
Freezes current plot.
Legend placement by mouse.
Redraws current figure window.
Specifies properties of objects such as axes.
Creates plots in subwindows.
Places string in figure.

Specialized Plot Commands
bar
loglog
polar
semilogx
semilogy
stairs
stem

Creates bar chart.
Creates log-log plot.
Creates polar plot.
Creates semilog plot (logarithmic abscissa).
Creates semilog plot (logarithmic ordinate).
Creates stairs pot.
Creates stem plot.

MATLAB Commands – 8
Colors, Symbols and Line Types
Color
y
m
c
r
g
b
w
k

yellow
magenta
cyan
red
green
blue
white
black

Symbol
.
o
x
+
*
d
v
^
<
>
p
h

point
circle
x-mark
plus
star
diamond
triangle (down)
triangle (up)
triangle (left)
triangle (right)
pentagram
hexagram

Line
:
-.
--

solid
dotted
dash dotted
dashed

Three-Dimensional Plotting Commands
contour
mesh
meshc
meshz
plot3
surf
surfc
meshgrid
waterfall
zlabel

Creates contour plot.
Creates three-dimensional mesh surface plot.
Same as mesh with contour plot underneath.
Same as mesh with vertical lines underneath.
Creates three-dimensional plots from lines and points.
Creates shaded three-dimensional mesh surface plot.
Same as surf with contour plot underneath.
Creates rectangular grid.
Same as mesh with mesh lines in one direction.
Adds text label to z-axis.

Histogram Functions
bar
hist
histc

Creates a bar chart.
Aggregates the data into equally spaced bins.
Aggregates the data into unequally spaced bins.

MATLAB Commands – 9
Programming
Logical and Relational Operators
==
~=
<
<=
>
>=
&
|
~
xor

Relational operator: equal to.
Relational operator: not equal to.
Relational operator: less than.
Relational operator: less than or equal to.
Relational operator: greater than.
Relational operator: greater than or equal to.
Logical operator: AND.
Logical operator: OR.
Logical operator: NOT.
Logical operator: EXCLUSIVE OR.

Program Flow Control
break
case
else
elseif
end
error
for
if
otherwise
return
switch
warning
while

Terminates execution of a loop.
Provides alternate execution paths within switch structure.
Delineates alternate block of statements.
Conditionally executes statements.
Terminates for, while, and if statements.
Display error messages.
Repeats statements a specific number of times
Executes statements conditionally.
Default part of switch statement.
Return to the invoking function.
Directs program execution by comparing point with case expressions.
Display a warning message.
Repeats statements an indefinite number of times.

Logical Functions
any
all
find
finite
isnan
isinf
isempty
isreal

True if any elements are nonzero.
True if all elements are nonzero.
Finds indices of nonzero elements.
True if elements are finite.
True if elements are undefined.
True if elements are infinite.
True if matrix is empty.
True if all elements are real.

MATLAB Commands – 10
M-Files
eval
feval
function
global
nargin
nargout
script

Interpret strings containing Matlab expressions.
Function evaluation.
Creates a user-defined function M-file.
Define global variables.
Number of function input arguments.
Number of function output arguments.
Script M-files

Timing
cputime
clock
tic, toc

CPU time in seconds.
Current date and time as date vector.
Start, stop a stopwatch timer.

MATLAB Commands – 11
Mathematical Functions
Exponential and Logarithmic Functions
exp(x)
log(x)
log10(x)
sqrt(x)

Exponential; ex.
Natural logarithm; ln(x).
Common (base 10) logarithm; log(x)= log10(x).
Square root; x.

Trigonometric Functions
acos(x)
acot(x)
acsc(x)
asec(x)
asin(x)
atan(x)
atan2(y,x)
cos(x)
cot(x)
csc(x)
sec(x)
sin(x)
tan(x)

Inverse cosine; arcos x = cos –1 (x).
Inverse cotangent; arccot x = cot –1(x).
Inverse cosecant; arcs x = csc –1 (x).
Inverse secant; arcsec x = sec –1 (x).
Inverse sine; arcsin x = sin –1 (x).
Inverse tangent; arctan x = tan –1 (x).
Four-quadrant inverse tangent.
Cosine; cos(x).
Cotangent; cot(x).
Cosecant; csc(x).
Secant; sec(x).
Sine; sin(x).
Tangent; tan(x).

Hyperbolic Functions
acosh(x)
acoth(x)
acsch(x)
asech(x)
asinh(x)
atanh(x)
cosh(x)
coth(x)
csch(x)
sech(x)
sinh(x)
tanh(x)

Inverse hyperbolic cosine; cosh –1 (x).
Inverse hyperbolic cotangent; coth –1 (x).
Inverse hyperbolic cosecant; csch –1 (x).
Inverse hyperbolic secant; sech –1 (x).
Inverse hyperbolic sine; sinh –1 (x).
Inverse hyperbolic tangent; tanh –1 (x).
Hyperbolic cosine; cosh(x).
Hyperbolic cotangent; cosh(x)/sinh(x).
Hyperbolic cosecant; 1/sinh(x).
Hyperbolic secant; 1/cosh(x).
Hyperbolic sine; sinh(x).
Hyperbolic tangent; sinh(x)/cosh(x).

MATLAB Commands – 12
Complex Functions
abs(x)
angle(x)
conj(x)
imag(x)
real(x)

Absolute value; |x|.
Angle of a complex number x.
Complex conjugate of x.
Imaginary part of a complex number x.
Real part of a complex number x.

Statistical Functions
erf(x)
mean
median
std

Computes the error function erf (x).
Calculates the average.
Calculates the median.
Calculates the standard deviation.

Random Number Functions
rand
randn

Generates uniformly distributed random numbers between 0 and 1.
Generates normally distributed random numbers.

Numeric Functions
ceil
fix
floor
round
sign

Rounds to the nearest integer toward •.
Rounds to the nearest integer toward zero.
Rounds to the nearest integer toward - •.
Rounds towards the nearest integer.
Signum function.

String Functions
findstr
strcmp
char

Finds occurrences of a string.
Compares strings.
Creates character string array

MATLAB Commands – 13
Numerical Methods
Polynomial and Regression Functions
conv
deconv
eig
poly
polyfit
polyval
roots

Computes product of two polynomials
Computes ratio of polynomials.
Computes the eigenvalues of a matrix.
Computes polynomial from roots.
Fits a polynomial to data.
Evaluates polynomial and generates error estimates.
Computes polynomial roots.

Interpolation Functions
interp1
interp2
spline
unmkpp

Linear and cubic-spline interpolations of a function of one variable.
Linear interpolation of a function of two variables.
Cubic-spline interpolation.
Computes the coefficients of cubic-spine polynomials.

Root Finding and Minimization
fmin
fmins
fzero

Finds minimum of single-variable function.
Finds minimum of multivariable function.
Finds zero of single-variable function.

Numerical Integration Functions
quad
quadl
trapz

Numerical integration with adaptive Simpson’s rule.
Numerical integration with adaptive Lobatto quadrature.
Numerical integration with the trapezoidal rule.

Numerical Differentiation Functions
diff(x)
polyder

Computes the difference between adjacent elements in the vector x.
Differentiates a polynomial, a polynomial product, or a polynomial quotient.

MATLAB Commands – 14
ODE Solvers
ode23
ode45
ode113
ode23s
ode23t
ode23b
ode15s
odeset

Nonstiff, low-order solver.
Nonstiff, medium-order solver.
Nonstiff, variable-order solver.
Stiff, low-order.
Moderately stiff, trapezoidal rule solver.
Stiff, low-order solver.
Stiff, variable-order solver.
Creates integrator options structure for ODE solvers.

Predefined Input Functions
gensig
sawtooth
square
stepfun

Generates a periodic sine, square, or pulse input.
Generates a periodic sawtooth input.
Generates a square wave input.
Generates a step function input.

MATLAB Commands – 15
Symbolic Math Toolbox
Functions for Creating and Evaluating Symbolic Expressions
class
digits
double
ezplot
findsym
numden
sym
syms
vpa

Returns the class of an expression.
Sets the number of decimal digits used to do variable precision arithmetic.
Converts an expression to numeric form.
Generates a plot of a symbolic expression.
Finds the symbolic variables in a symbolic expression.
Returns the numerator and denominator of an expression.
Creates a symbolic variable.
Creates one or more symbolic variables.
Sets the number of digits used to evaluate expressions.

Functions for Manipulating Symbolic Expressions
collect
expand
factor
poly2sym
pretty
simple
simplify
subs
sym2poly

Collects coefficients of like powers in an expression.
Expands an expression by carrying out jpowers.
Factors an expression.
Converts a polynomial coefficient vector to a symbolic polynomial.
Displays an expression in a form that resembles typeset mathematics.
Searches for the shortest form of an expression.
Simplifies an expression using Maple’s simplification rules.
Substitutes variables or expressions.
Converts an expression to a polynomial coefficient vector.

Symbolic Calculus Functions
diff
Dirac
Heaviside
int
limit
symsum
taylor

Returns the derivative of an expression.
Dirac delta function (unit impulse).
Heaviside function (unit step).
Returns the integral of an expression.
Returns the limit of an expression.
Returns the symbolic summation of an expression.
Returns the Taylor series of a function.

MATLAB Commands – 16
Symbolic Solution of Algebraic and Transcendental Equations
solve

Solves symbolic equations.

Symbolic Solution of Differential Equations
dsolve

Returns a symbolic solution of a differential equation or set of equations.

Laplace Transform Functions
ilaplace
laplace

Returns the inverse Laplace transform.
Returns the Laplace transform.

Symbolic Linear Algebra Functions
det
eig
inv
poly

Returns the determinant of a matrix.
Returns the eigenvalues (characteristic roots) of a matrix.
Returns the inverse of a matrix.
Returns the characteristic polynomial of a matrix.

MATLAB Commands – 17

Mais conteúdo relacionado

Mais procurados

MATRICES
MATRICESMATRICES
MATRICES
faijmsk
 
User-­friendly Metaworkflows in Quantum Chemistry
User-­friendly Metaworkflows in Quantum ChemistryUser-­friendly Metaworkflows in Quantum Chemistry
User-­friendly Metaworkflows in Quantum Chemistry
Sandra Gesing
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
Santosh V
 

Mais procurados (20)

MATRICES
MATRICESMATRICES
MATRICES
 
Random number generation
Random number generationRandom number generation
Random number generation
 
Matrix algebra
Matrix algebraMatrix algebra
Matrix algebra
 
Multivariate and Conditional Distribution
Multivariate and Conditional DistributionMultivariate and Conditional Distribution
Multivariate and Conditional Distribution
 
User-­friendly Metaworkflows in Quantum Chemistry
User-­friendly Metaworkflows in Quantum ChemistryUser-­friendly Metaworkflows in Quantum Chemistry
User-­friendly Metaworkflows in Quantum Chemistry
 
Unit 3 random number generation, random-variate generation
Unit 3 random number generation, random-variate generationUnit 3 random number generation, random-variate generation
Unit 3 random number generation, random-variate generation
 
pca.ppt
pca.pptpca.ppt
pca.ppt
 
Hidden Markov Model - The Most Probable Path
Hidden Markov Model - The Most Probable PathHidden Markov Model - The Most Probable Path
Hidden Markov Model - The Most Probable Path
 
NUMERICAL INTEGRATION AND ITS APPLICATIONS
NUMERICAL INTEGRATION AND ITS APPLICATIONSNUMERICAL INTEGRATION AND ITS APPLICATIONS
NUMERICAL INTEGRATION AND ITS APPLICATIONS
 
Basic matlab and matrix
Basic matlab and matrixBasic matlab and matrix
Basic matlab and matrix
 
Lasso and ridge regression
Lasso and ridge regressionLasso and ridge regression
Lasso and ridge regression
 
Stat 2153 Stochastic Process and Markov chain
Stat 2153 Stochastic Process and Markov chainStat 2153 Stochastic Process and Markov chain
Stat 2153 Stochastic Process and Markov chain
 
Introduction to Latex
Introduction to LatexIntroduction to Latex
Introduction to Latex
 
The Multivariate Gaussian Probability Distribution
The Multivariate Gaussian Probability DistributionThe Multivariate Gaussian Probability Distribution
The Multivariate Gaussian Probability Distribution
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matrix and its operation (addition, subtraction, multiplication)
Matrix and its operation (addition, subtraction, multiplication)Matrix and its operation (addition, subtraction, multiplication)
Matrix and its operation (addition, subtraction, multiplication)
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Presentation on Numerical Integration
Presentation on Numerical IntegrationPresentation on Numerical Integration
Presentation on Numerical Integration
 
4. random number and it's generating techniques
4. random number and it's generating techniques 4. random number and it's generating techniques
4. random number and it's generating techniques
 
Solution of N Queens Problem genetic algorithm
Solution of N Queens Problem genetic algorithm  Solution of N Queens Problem genetic algorithm
Solution of N Queens Problem genetic algorithm
 

Semelhante a Matlab commands

matlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsxmatlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsx
lekhacce
 

Semelhante a Matlab commands (20)

Matlab commands
Matlab commandsMatlab commands
Matlab commands
 
Matlab commands
Matlab commandsMatlab commands
Matlab commands
 
matlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsxmatlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsx
 
Matlab basic and image
Matlab basic and imageMatlab basic and image
Matlab basic and image
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
 
Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
 
EPE821_Lecture3.pptx
EPE821_Lecture3.pptxEPE821_Lecture3.pptx
EPE821_Lecture3.pptx
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 

Mais de Tarun Gehlot

Mais de Tarun Gehlot (20)

Materials 11-01228
Materials 11-01228Materials 11-01228
Materials 11-01228
 
Binary relations
Binary relationsBinary relations
Binary relations
 
Continuity and end_behavior
Continuity and  end_behaviorContinuity and  end_behavior
Continuity and end_behavior
 
Continuity of functions by graph (exercises with detailed solutions)
Continuity of functions by graph   (exercises with detailed solutions)Continuity of functions by graph   (exercises with detailed solutions)
Continuity of functions by graph (exercises with detailed solutions)
 
Factoring by the trial and-error method
Factoring by the trial and-error methodFactoring by the trial and-error method
Factoring by the trial and-error method
 
Introduction to finite element analysis
Introduction to finite element analysisIntroduction to finite element analysis
Introduction to finite element analysis
 
Finite elements : basis functions
Finite elements : basis functionsFinite elements : basis functions
Finite elements : basis functions
 
Finite elements for 2‐d problems
Finite elements  for 2‐d problemsFinite elements  for 2‐d problems
Finite elements for 2‐d problems
 
Error analysis statistics
Error analysis   statisticsError analysis   statistics
Error analysis statistics
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Linear approximations and_differentials
Linear approximations and_differentialsLinear approximations and_differentials
Linear approximations and_differentials
 
Local linear approximation
Local linear approximationLocal linear approximation
Local linear approximation
 
Interpolation functions
Interpolation functionsInterpolation functions
Interpolation functions
 
Propeties of-triangles
Propeties of-trianglesPropeties of-triangles
Propeties of-triangles
 
Gaussian quadratures
Gaussian quadraturesGaussian quadratures
Gaussian quadratures
 
Basics of set theory
Basics of set theoryBasics of set theory
Basics of set theory
 
Numerical integration
Numerical integrationNumerical integration
Numerical integration
 
Applications of set theory
Applications of  set theoryApplications of  set theory
Applications of set theory
 
Miscellneous functions
Miscellneous  functionsMiscellneous  functions
Miscellneous functions
 
Dependent v. independent variables
Dependent v. independent variablesDependent v. independent variables
Dependent v. independent variables
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Último (20)

HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 

Matlab commands

  • 1. MATLAB Commands and Functions Dr. Brian Vick Mechanical Engineering Department Virginia Tech General Purpose Commands Operators and Special Characters / 3 Commands for Managing a Session / 3 Special Variables and Constants / 4 System and File Commands / 4 Input/Output and Formatting Commands Input/Output Commands / 5 Format Codes for fprintf and fscanf / 5 Numeric Display Formats / 5 Vector, Matrix and Array Commands Array Commands / 6 Special Matrices / 6 Matrix Arithmetic / 6 Matrix Commands for Solving Linear Equations / 6 Cell Array Functions / 7 Structure Functions / 7 Plotting Commands Basic xy Plotting Commands / 8 Plot Enhancement Commands / 8 Specialized Plot Commands / 8 Colors, Symbols and Line Types / 9 Three-Dimensional Plotting Commands / 9 Histogram Functions / 9 MATLAB Commands – 1
  • 2. Programming Logical and Relational Operators / 10 Program Flow Control / 10 Logical Functions / 10 M-Files / 11 Timing /11 Mathematical Functions Exponential and Logarithmic Functions / 12 Trigonometric Functions / 12 Hyperbolic Functions / 12 Complex Functions / 13 Statistical Functions / 13 Random Number Functions / 13 Numeric Functions / 13 String Functions / 13 Numerical Methods Polynomial and Regression Functions / 14 Interpolation Functions / 14 Numerical Integration Functions / 14 Numerical Differentiation Functions / 14 ODE Solvers / 15 Predefined Input Functions / 15 Symbolic Math Toolbox Functions for Creating and Evaluating Symbolic Expressions / 16 Functions for Manipulating Symbolic Expressions / 16 Symbolic Calculus Functions / 16 Symbolic Solution of Algebraic and Transcendental Equations / 17 Symbolic Solution of Differential Equations / 17 Laplace Transform Functions / 17 Symbolic Linear Algebra Functions / 17 MATLAB Commands – 2
  • 3. General Purpose Commands Operators and Special Characters + * .* ^ .^ / . ./ : ( ) [ ] . … , ; % _ ._ = Plus; addition operator. Minus; subtraction operator. Scalar and matrix multiplication operator. Array multiplication operator. Scalar and matrix exponentiation operator. Array exponentiation operator. Left-division operator. Right-division operator. Array left-division operator. Array right-division operator. Colon; generates regularly spaced elements and represents an entire row or column. Parentheses; encloses function arguments and array indices; overrides precedence. Brackets; enclosures array elements. Decimal point. Ellipsis; line-continuation operator. Comma; separates statements and elements in a row. Semicolon; separates columns and suppresses display. Percent sign; designates a comment and specifies formatting. Quote sign and transpose operator. Nonconjugated transpose operator. Assignment (replacement) operator. Commands for Managing a Session clc clear exist global help lookfor quit who whos Clears Command window. Removes variables from memory. Checks for existence of file or variable. Declares variables to be global. Searches for a help topic. Searches help entries for a keyword. Stops MATLAB. Lists current variables. Lists current variables (long display). MATLAB Commands – 3
  • 4. Special Variables and Constants ans eps i,j Inf NaN pi Most recent answer. Accuracy of floating-point precision. The imaginary unit - 1. Infinity. Undefined numerical result (not a number). The number p . System and File Commands cd date delete diary dir load path pwd save type what wklread Changes current directory. Displays current date. Deletes a file. Switches on/off diary file recording. Lists all files in current directory. Loads workspace variables from a file. Displays search path. Displays current directory. Saves workspace variables in a file. Displays contents of a file. Lists all MATLAB files in the current directory. Reads .wk1 spreadsheet file. MATLAB Commands – 4
  • 5. Input/Output and Formatting Commands Input/Output Commands disp fscanf format fprintf input ; Displays contents of an array or string. Read formatted data from a file. Controls screen-display format. Performs formatted writes to screen or file. Displays prompts and waits for input. Suppresses screen printing. Format Codes for fprintf and fscanf %s %d %f %e %g n t Format as a string. Format as an integer. Format as a floating point value. Format as a floating point value in scientific notation. Format in the most compact form: %f or %e. Insert a new line in the output string. Insert a tab in the output string. Numeric Display Formats format format format format format format format format format short long short e long e bank + rat compact loose Four decimal digits (default). 16 decimal digits. Five digits plus exponent. 16 digits plus exponents. Two decimal digits. Positive, negative, or zero. Rational approximation. Suppresses some line feeds. Resets to less compact display mode. MATLAB Commands – 5
  • 6. Vector, Matrix and Array Commands Array Commands cat find length linspace logspace max min prod reshape size sort sum Concatenates arrays. Finds indices of nonzero elements. Computers number of elements. Creates regularly spaced vector. Creates logarithmically spaced vector. Returns largest element. Returns smallest element. Product of each column. Change size Computes array size. Sorts each column. Sums each column. Special Matrices eye ones zeros Creates an identity matrix. Creates an array of ones. Creates an array of zeros. Matrix Arithmetic cross dot Computes cross products. Computes dot products. Matrix Commands for Solving Linear Equations det inv pinv rank rref Computes determinant of an array. Computes inverse of a matrix. Computes pseudoinverse of a matrix. Computes rank of a matrix. Computes reduced row echelon form. MATLAB Commands – 6
  • 7. Cell Array Functions cell celldisp cellplot num2cell deal iscell Creates cell array. Displays cell array. Displays graphical representation of cell array. Converts numeric array to cell array. Matches input and output lists. Identifies cell array. Structure Functions fieldnames getfield isfield isstruct rmfield setfield struct Returns field names in a structure array. Returns field contents of a structure array. Identifies a structure array field. Identifies a structure array. Removes a field from a structure array. Sets contents of field. Creates structure array. MATLAB Commands – 7
  • 8. Plotting Commands Basic xy Plotting Commands axis fplot grid plot print title xlabel ylabel Sets axis limits. Intelligent plotting of functions. Displays gridlines. Generates xy plot. Prints plot or saves plot to a file Puts text at top of plot. Adds text label to x-axis. Adds text label to y-axis. Plot Enhancement Commands axes close close all figure gtext hold legend refresh set subplot text Creates axes objects. Closes the current plot. Closes all plots. Opens a new figure window. Enables label placement by mouse. Freezes current plot. Legend placement by mouse. Redraws current figure window. Specifies properties of objects such as axes. Creates plots in subwindows. Places string in figure. Specialized Plot Commands bar loglog polar semilogx semilogy stairs stem Creates bar chart. Creates log-log plot. Creates polar plot. Creates semilog plot (logarithmic abscissa). Creates semilog plot (logarithmic ordinate). Creates stairs pot. Creates stem plot. MATLAB Commands – 8
  • 9. Colors, Symbols and Line Types Color y m c r g b w k yellow magenta cyan red green blue white black Symbol . o x + * d v ^ < > p h point circle x-mark plus star diamond triangle (down) triangle (up) triangle (left) triangle (right) pentagram hexagram Line : -. -- solid dotted dash dotted dashed Three-Dimensional Plotting Commands contour mesh meshc meshz plot3 surf surfc meshgrid waterfall zlabel Creates contour plot. Creates three-dimensional mesh surface plot. Same as mesh with contour plot underneath. Same as mesh with vertical lines underneath. Creates three-dimensional plots from lines and points. Creates shaded three-dimensional mesh surface plot. Same as surf with contour plot underneath. Creates rectangular grid. Same as mesh with mesh lines in one direction. Adds text label to z-axis. Histogram Functions bar hist histc Creates a bar chart. Aggregates the data into equally spaced bins. Aggregates the data into unequally spaced bins. MATLAB Commands – 9
  • 10. Programming Logical and Relational Operators == ~= < <= > >= & | ~ xor Relational operator: equal to. Relational operator: not equal to. Relational operator: less than. Relational operator: less than or equal to. Relational operator: greater than. Relational operator: greater than or equal to. Logical operator: AND. Logical operator: OR. Logical operator: NOT. Logical operator: EXCLUSIVE OR. Program Flow Control break case else elseif end error for if otherwise return switch warning while Terminates execution of a loop. Provides alternate execution paths within switch structure. Delineates alternate block of statements. Conditionally executes statements. Terminates for, while, and if statements. Display error messages. Repeats statements a specific number of times Executes statements conditionally. Default part of switch statement. Return to the invoking function. Directs program execution by comparing point with case expressions. Display a warning message. Repeats statements an indefinite number of times. Logical Functions any all find finite isnan isinf isempty isreal True if any elements are nonzero. True if all elements are nonzero. Finds indices of nonzero elements. True if elements are finite. True if elements are undefined. True if elements are infinite. True if matrix is empty. True if all elements are real. MATLAB Commands – 10
  • 11. M-Files eval feval function global nargin nargout script Interpret strings containing Matlab expressions. Function evaluation. Creates a user-defined function M-file. Define global variables. Number of function input arguments. Number of function output arguments. Script M-files Timing cputime clock tic, toc CPU time in seconds. Current date and time as date vector. Start, stop a stopwatch timer. MATLAB Commands – 11
  • 12. Mathematical Functions Exponential and Logarithmic Functions exp(x) log(x) log10(x) sqrt(x) Exponential; ex. Natural logarithm; ln(x). Common (base 10) logarithm; log(x)= log10(x). Square root; x. Trigonometric Functions acos(x) acot(x) acsc(x) asec(x) asin(x) atan(x) atan2(y,x) cos(x) cot(x) csc(x) sec(x) sin(x) tan(x) Inverse cosine; arcos x = cos –1 (x). Inverse cotangent; arccot x = cot –1(x). Inverse cosecant; arcs x = csc –1 (x). Inverse secant; arcsec x = sec –1 (x). Inverse sine; arcsin x = sin –1 (x). Inverse tangent; arctan x = tan –1 (x). Four-quadrant inverse tangent. Cosine; cos(x). Cotangent; cot(x). Cosecant; csc(x). Secant; sec(x). Sine; sin(x). Tangent; tan(x). Hyperbolic Functions acosh(x) acoth(x) acsch(x) asech(x) asinh(x) atanh(x) cosh(x) coth(x) csch(x) sech(x) sinh(x) tanh(x) Inverse hyperbolic cosine; cosh –1 (x). Inverse hyperbolic cotangent; coth –1 (x). Inverse hyperbolic cosecant; csch –1 (x). Inverse hyperbolic secant; sech –1 (x). Inverse hyperbolic sine; sinh –1 (x). Inverse hyperbolic tangent; tanh –1 (x). Hyperbolic cosine; cosh(x). Hyperbolic cotangent; cosh(x)/sinh(x). Hyperbolic cosecant; 1/sinh(x). Hyperbolic secant; 1/cosh(x). Hyperbolic sine; sinh(x). Hyperbolic tangent; sinh(x)/cosh(x). MATLAB Commands – 12
  • 13. Complex Functions abs(x) angle(x) conj(x) imag(x) real(x) Absolute value; |x|. Angle of a complex number x. Complex conjugate of x. Imaginary part of a complex number x. Real part of a complex number x. Statistical Functions erf(x) mean median std Computes the error function erf (x). Calculates the average. Calculates the median. Calculates the standard deviation. Random Number Functions rand randn Generates uniformly distributed random numbers between 0 and 1. Generates normally distributed random numbers. Numeric Functions ceil fix floor round sign Rounds to the nearest integer toward •. Rounds to the nearest integer toward zero. Rounds to the nearest integer toward - •. Rounds towards the nearest integer. Signum function. String Functions findstr strcmp char Finds occurrences of a string. Compares strings. Creates character string array MATLAB Commands – 13
  • 14. Numerical Methods Polynomial and Regression Functions conv deconv eig poly polyfit polyval roots Computes product of two polynomials Computes ratio of polynomials. Computes the eigenvalues of a matrix. Computes polynomial from roots. Fits a polynomial to data. Evaluates polynomial and generates error estimates. Computes polynomial roots. Interpolation Functions interp1 interp2 spline unmkpp Linear and cubic-spline interpolations of a function of one variable. Linear interpolation of a function of two variables. Cubic-spline interpolation. Computes the coefficients of cubic-spine polynomials. Root Finding and Minimization fmin fmins fzero Finds minimum of single-variable function. Finds minimum of multivariable function. Finds zero of single-variable function. Numerical Integration Functions quad quadl trapz Numerical integration with adaptive Simpson’s rule. Numerical integration with adaptive Lobatto quadrature. Numerical integration with the trapezoidal rule. Numerical Differentiation Functions diff(x) polyder Computes the difference between adjacent elements in the vector x. Differentiates a polynomial, a polynomial product, or a polynomial quotient. MATLAB Commands – 14
  • 15. ODE Solvers ode23 ode45 ode113 ode23s ode23t ode23b ode15s odeset Nonstiff, low-order solver. Nonstiff, medium-order solver. Nonstiff, variable-order solver. Stiff, low-order. Moderately stiff, trapezoidal rule solver. Stiff, low-order solver. Stiff, variable-order solver. Creates integrator options structure for ODE solvers. Predefined Input Functions gensig sawtooth square stepfun Generates a periodic sine, square, or pulse input. Generates a periodic sawtooth input. Generates a square wave input. Generates a step function input. MATLAB Commands – 15
  • 16. Symbolic Math Toolbox Functions for Creating and Evaluating Symbolic Expressions class digits double ezplot findsym numden sym syms vpa Returns the class of an expression. Sets the number of decimal digits used to do variable precision arithmetic. Converts an expression to numeric form. Generates a plot of a symbolic expression. Finds the symbolic variables in a symbolic expression. Returns the numerator and denominator of an expression. Creates a symbolic variable. Creates one or more symbolic variables. Sets the number of digits used to evaluate expressions. Functions for Manipulating Symbolic Expressions collect expand factor poly2sym pretty simple simplify subs sym2poly Collects coefficients of like powers in an expression. Expands an expression by carrying out jpowers. Factors an expression. Converts a polynomial coefficient vector to a symbolic polynomial. Displays an expression in a form that resembles typeset mathematics. Searches for the shortest form of an expression. Simplifies an expression using Maple’s simplification rules. Substitutes variables or expressions. Converts an expression to a polynomial coefficient vector. Symbolic Calculus Functions diff Dirac Heaviside int limit symsum taylor Returns the derivative of an expression. Dirac delta function (unit impulse). Heaviside function (unit step). Returns the integral of an expression. Returns the limit of an expression. Returns the symbolic summation of an expression. Returns the Taylor series of a function. MATLAB Commands – 16
  • 17. Symbolic Solution of Algebraic and Transcendental Equations solve Solves symbolic equations. Symbolic Solution of Differential Equations dsolve Returns a symbolic solution of a differential equation or set of equations. Laplace Transform Functions ilaplace laplace Returns the inverse Laplace transform. Returns the Laplace transform. Symbolic Linear Algebra Functions det eig inv poly Returns the determinant of a matrix. Returns the eigenvalues (characteristic roots) of a matrix. Returns the inverse of a matrix. Returns the characteristic polynomial of a matrix. MATLAB Commands – 17