0% found this document useful (0 votes)
15 views

Matlab Commands

The document provides an overview of MATLAB commands and functions organized into categories including general purpose commands, input/output and formatting commands, vector/matrix commands, plotting commands, programming commands, and mathematical functions. It lists numerous commands and their purposes in a concise reference format.

Uploaded by

cybermonks222
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Matlab Commands

The document provides an overview of MATLAB commands and functions organized into categories including general purpose commands, input/output and formatting commands, vector/matrix commands, plotting commands, programming commands, and mathematical functions. It lists numerous commands and their purposes in a concise reference format.

Uploaded by

cybermonks222
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

MATLAB Commands and Functions

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.
= Assignment (replacement) operator.

Commands for Managing a Session


clc Clears Command window.
clear Removes variables from memory.
help Searches for a help topic.
quit Stops MATLAB.

Special Variables and Constants


ans Most recent answer.
i,j The imaginary unit - 1.
Inf Infinity.
NaN Undefined numerical result (not a number).
pi The number .
Input / Output and Formatting Commands

Input / Output Commands


disp Displays contents of an array or string.
fscanf Read formatted data from a file.
fprintf Performs formatted writes to screen or file.
input Displays prompts and waits for input.
; Suppresses screen printing.

Format Codes for fprintf and fscanf


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

Vector, Matrix and Array Commands

Array Commands
length Computers number of elements.
max Returns largest element.
min Returns smallest element.
prod Product of each column.
size Computes array size.
sort Sorts each column.
sum Sums each column.

Special Matrices
eye Creates an identity matrix.
ones Creates an array of ones.
zeros Creates an array of zeros.

Matrix Arithmetic
cross Computes cross products.
dot Computes dot products.
Matrix Commands for Solving Linear Equations
det Computes determinant of an array.
inv Computes inverse of a matrix.
pinv Computes pseudo inverse of a matrix.
rank Computes rank of a matrix.

Plotting Commands

Basic xy Plotting Commands


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

Plot Enhancement Commands


axes Creates axes objects.
close Closes the current plot.
close all Closes all plots.
figure Opens a new figure window.
hold Freezes current plot.
legend Legend placement by mouse.
refresh Redraws current figure window.
subplot Creates plots in subwindows.
text Places string in figure.

Specialized Plot Commands


bar Creates bar chart.
loglog Creates log-log plot.
polar Creates polar plot.
semilogx Creates semilog plot (logarithmic abscissa).
semilogy Creates semilog plot (logarithmic ordinate).
Colors, Symbols and Line Types
Color Symbol Line
y yellow . Point - solid
m magenta o Circle : dotted
c cyan x x-mark -. dash dotted
r red + Plus -- dashed
g green * Star
b blue d diamond
w white v triangle (down)
k black ^ triangle (up)
< triangle (left)
> triangle (right)
p pentagram
h hexagram

Programming

Logical and Relational Operators


== 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.
xor Logical operator: EXCLUSIVE OR.

Program Flow Control


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

Mathematical Functions

Exponential and Logarithmic Functions


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

Trigonometric Functions
acos(x) Inverse cosine; arcos x = cos –1 (x).
acot(x) Inverse cotangent; arccot x = cot –1(x).
acsc(x) Inverse cosecant; arcs x = csc –1 (x).
asec(x) Inverse secant; arcsec x = sec –1 (x).
asin(x) Inverse sine; arcsin x = sin –1 (x).
atan(x) Inverse tangent; arctan x = tan –1 (x).
cos(x) Cosine; cos(x).
cot(x) Cotangent; cot(x).
csc(x) Cosecant; csc(x).
sec(x) Secant; sec(x).
sin(x) Sine; sin(x).
tan(x) Tangent; tan(x).

Hyperbolic Functions
acosh(x) Inverse hyperbolic cosine; cosh –1 (x).
acoth(x) Inverse hyperbolic cotangent; coth –1 (x).
acsch(x) Inverse hyperbolic cosecant; csch –1 (x).
asech(x) Inverse hyperbolic secant; sech –1 (x).
asinh(x) Inverse hyperbolic sine; sinh –1 (x).
atanh(x) Inverse hyperbolic tangent; tanh –1 (x).
cosh(x) Hyperbolic cosine; cosh(x).
coth(x) Hyperbolic cotangent; cosh(x)/sinh(x).
csch(x) Hyperbolic cosecant; 1/sinh(x).
sech(x) Hyperbolic secant; 1/cosh(x).
sinh(x) Hyperbolic sine; sinh(x).
tanh(x) Hyperbolic tangent; sinh(x)/cosh(x).
Complex Functions
abs(x) Absolute value; |x|.
angle(x) Angle of a complex number x.
conj(x) Complex conjugate of x.
imag(x) Imaginary part of a complex number x.
real(x) Real part of a complex number x.

Numerical Methods

Polynomial and Regression Functions


conv Computes product of two polynomials
deconv Computes ratio of polynomials.
eig Computes the eigen values of a matrix.
poly Computes polynomial from roots.
polyfit Fits a polynomial to data.
polyval Evaluates polynomial and generates error estimates.
roots Computes polynomial roots.

You might also like