Matlab Commands
Matlab Commands
help fun Display in-line help for fun A = [1 2 3; 4 5 6] Define A as a 2x3 matrix
A = [1 2 3
doc fun Open documentation for fun “space” separates columns
examplescript
x(1:2:end) Get every 2nd element of x (1st to last)
Operators and Special Characters A(6, 2:5) Get 2nd to 5th element in 6th row of A
transpose values
... Connect lines (with break) x=diag(A) Get diagonal elements of matrix
'Hello' Definition of a character vector rand(m,n), randi Create uniformly distributed random
Definition of a string
randn(m,n) Create normally distributed random
NaN, nan Not a number (i.e., division by zero) angle(z) Phase angle in radians
mathworks.com/help/matlab
sin(x), asin Sine and inverse (argument in radians) plot(x,y,LineSpec) Plot y vs. x
sinh(x), asinh Hyperbolic sine and inverse (arg. in Markers: linestyle, marker, and
cos, tan, csc, sec, and cot r, g, b, c, m, y, k, w = red solid line without markers
title("Title")
abs(x) Absolute value of x, complex magnitude Add plot title
sqrt(x), nthroot(x,n) Square root, real nth root of real numbers x/y/zlabel("label") Add x/y/z axis label
log2(x), log10 Logarithm with base 2 and 10, respectively x/y/zticklabels(labels) Get or set x/y/z axis tick labels
mod(x,d) Remainder after division (modulo) axis(lim), axis style Set axis limits and style
ceil(x), fix, floor Round toward +inf, 0, -inf text(x,y,"txt") Add text
round(x) Round to nearest decimal or integer grid on/off Show axis grid
array2table(A) Convert numeric array to table gcf, gca Get current figure, get current axis
T.var Extract data from variable var clf Clear current figure
T(rows,columns), Create a new table with specified close all Close open figures
Live Editor tasks are apps that can be added to a live script to interactively
commands. To see the commands that the task runs, show the generated
code.
desktop toolstrip:
mathworks.com/help/matlab
% Save your function in a function file or at the end fminsearch(fun,x0) Find minimum of function
function cavg = cumavg(x) %multiple args. possible fft(x), ifft(x) Fast Fourier transform and its inverse
cavg=cumsum(vec)./(1:length(vec));
end
Integration and Differentiation
Anonymous Functions
else
switch n bc,xm,ts)
interp1(x,v,xq) 1D interpolation
end % control structures terminate with end
For-Loop
pchip(x,v,xq) Piecewise cubic Hermite polynomial
disp("cool");
poly(x)
% loops as long as a condition remains true Polynomial with specified roots x
nFactorial = 1; problem
n = n + 1;
polyfit(x,y,d) Polynomial curve fitting
mathworks.com/help/matlab
length(A) Length of largest array dimension sum(A), prod Sum or product (along columns)
size(A) Array dimensions max(A), min, bounds Largest and smallest element
sortrows(A) Sort rows of array or table movsum(A,n), movprod, Moving statistical functions
cummax, cummin
repmat(A,n) Repeat copies of array
Linear Algebra
detrend(x) Remove polynomial trend
eqn = y == 2*a + b
inv(A), pinv Inverse and pseudo inverse of matrix Define a symbolic equation
symbolic object
linsolve(A,B) Solve linear system of the form AX=B
lsqminnorm(A,B) Least-squares solution to linear equation fsurf, fmesh, fimplicit symbolic expressions
mathworks.com/help/matlab
© 2021 The MathWorks, Inc. MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See mathworks.com/trademarks for a list of additional trademarks.
Other product or brand names may be trademarks or registered trademarks of their respective holders.
disp('Name');
disp(num2str(Parameter,pr));