Você está na página 1de 2

Basics

save file.mat

saveallvariablestofile.mat
load file.mat

loadvariablefromfile.mat
whos

listallvariablesintheworkspace
clear

deleteallvariables
clear VarName1 VarName2
deleteVarName1andVarName2
CTRL+C

stopMATLAB,goodforinfiniteloops

Vectors/Matrices
x=[start:step_size:stop]

standardnotationforavector
X=[row 1 values; row 2 values; ]
standardnotationforamatrix
x'ortranspose(x)

transposex

PositionsinMatrices
x(2:1:12)
the2ndtothe12thelementsofx
x(1:3:end)
every3rdelementofx,startingatthe1standcontinuingtotheend
A(5,:)
the5throw,allcolumnsofA
A(:,8)
allrows,the8thcolumnofA
A(2:3,4:5)
the2ndand3rdrows,4thand5thcolumnsofA

CommonMatrices
rand(N,M)

NxMmatrixofrandomnumbersbetween0and1
randi([min max],N, M) NxMmatrixofrandomintegersbetweenminandmax
ones(N,M)

NxMmatrixofones
zeros(N,M)

NxMmatrixofzeros
eye(N)

NxNidentitymatrix
linspace(A,B,N)
1xNvectoroffromAtoB,equallyspaced
[]

Emptymatrix
a(1:3,:) = []
Removesrows13,allcolumnsfrommatrixa.

ValueManipulation
round()
roundanumbertothenearestinteger
floor()
nearestintegerbelowthenumber
ceil()
nearestintegerabovethenumber
abs()
theabsolutevalueormagnitudeofthenumber
real()
therealcomponentofanumber
imag()
theimaginarycomponentofanumber
angle()
theangledefinedbyanumbersreal/imaginarycomponents

TypeConversion
num2str()
convertnumbertoastring
str2num()
convertstringtonumber
rad2deg()
convertradianstodegrees

Interpolation
interp1(x,y,xi)
1Dinterpolationatxigivenvaluesydefinedatx
interp2(X,Y,Z,Xi,Yi) 2DinterpolationatXiandYigivenvaluesZdefinedatXandYpairs

ElementbyElementMath
.*
elementbyelementmultiplicationformatrices
./
elementbyelementdivisionformatrices
.^x
raiseeachelementtothepowerofx

Loops
while (test is true)
for i=1:total_iterations
<additionalcommands>
<additionalcommands>
end
end
*BEWAREINFINITELOOPS*

LogicalTests
if (logical test 1)
<additionalcommands>
elseif (logical test 2 if logical test 1 fails)
<additionalcommands>

elseif (logical test N if logical tests 1 to N-1 fail)


<additionalcommands>
else
<additionalcommands>
end

Plotting
figure

createanewfigure
figure(100)

createorrecallFigure100
plot(x, y , Option, Option Value)standardline/scatterplot
AdditionalOptionsInclude:
Color

linecolor:b,g,r,c,m,y,k,w,ora1x3(RGB)vectorfrom01
LineWidth
thewidthoftheline,anumber
LineStyle
linestyle:,:,.,,none
Marker
markerstyle:.,o,x,+,*,s,d,v,^,<,>,p,h
MarkerSize
markersize,anumber
MarkerFaceColor colorofthemarkersinterior,seeColorabove
MarkerEdgeColor colorofmarkersborder,seeColorabove
subplot(Rows, Cols, position) toputmultipleaxesononefigure,followedbyplot()
hold <on/off>
keep previous plot(s) in figure or erase them
box <on/off>

turnthebox(blacklinearoundtheentireplot)onoroff
grid <on/off>
turnthegridlinesintheplotonoroff
xlim([x_min x_max])
limitsofthexaxis,alsoappliestoylim()
xlabel(x axis label, Option, Option Value)
AdditionalOptionsInclude:
FontSize
Fontsize,anumber
FontWeight
Fontstyle:bold,italic,normal
Specialcharacters:\mufor,\sigmaforand\pifor(manyothers)
Alsoappliestoylabel(), title(), and legend()

DifferentialEquations
roots([coefficients])

roots/Eigenvaluesofthesystem
zplane(zeros,poles)

plotpolesandzerosinthezplane
dsolve(Eqn,Initial Condition(s)) solveadifferentialequation
diff()

takethe1stdifferenceorderivative
int()

integrateasymbolicequation
eval()

evaluatestringasifitwereacommand

Fourier( )andLaplace()Transforms
heaviside()

equivalenttothestepfunctionu(t)
fourier(symbolic expression, t, omega)
symbolic
ifourier(symbolic expression, omega, t)
symbolicinverse
laplace(symbolic expression, t, s)
symbolic

ilaplace(symbolic expression, s, t)
symbolicinverse
ofasignal
fft(y*dt)

ifft(Y/dt)

Inverse ofasignal
fftshift()

Shifts sothat0Hz(DC)isatthecenter

TransferFunctions(TF)
tf(num,denom)

createaTFgiventhenumeratoranddenominatorcoefficients
tf2zp(num,denom)

findzeros,poles,andgainsofsystem
pzmap(TF)

plotthepolesandzerosofatransferfunction
lsim(TF,input_signal,t)
simulatesystemresponsetoaninputsignalovertime

Filters
buttord(Wp,Ws,Gp,Gs,s)
calculateorderandcutofffrequencyofaButterworthfilter
givenpassbandandstopbandfrequenciesandpassbandand
stopbandgains.
cheyb1ord(Wp,Ws,Rp,Rs,s)
CalculateorderandcutofffrequencyofaChebychevfilter
givenpassbandandstopbandfrequenciesandpassbandand
stopbandripple.
butter(n,Wc,type,s)
calculatethenumeratoranddenominatorcoefficientsof
Butterworthfilter
calculatethenumeratoranddenominatorcoefficientsof
cheby1(n,Rp,Wp,type,s)
Chebychevfilter
bilinear(num, denom, Fs)
convertsanalogtodigitalfilter;usedbeforefilter()
filter(num,denom,signal)
filtersthesignalusingadigitalfilterdefinedbythenumerator
anddenominatorcoefficients
bodeplot(filter_TF)

createaBodeplotofthefilterdescribedbyatransferfunction

Structures
StructureName.FieldName

syntaxforaddressingafieldofastructure
fieldnames(StructureName)

listoffieldnameswithinthestructure
isfield(StructureName, FieldName) testtodetermineifthefieldexistsinthestructure
StructureName=rmfield(StructureName, FieldName)
removefieldfromastructure

Você também pode gostar