Download as pdf
Download as pdf
You are on page 1of 2
MATLAB CHEAT SHEET Throughout this document » and y will be either row or column vectors and A will always be a matrix. ‘lear command window clear Car all variables elf Clear all plots close at (lose al plots doe function Open helo page for function % This is a coment Comments ctrl-c Fornat short Format Long [Abort the eurent operation Display 4 decimal places Display 15 decimal places a ean ~ _ ax) az3 Define variable a to be 3 eig(a) x=, 2,31 Set 2 to be the row vector (1,23) size(a) ———— eens x22) ene sae x(2) = 7 ‘Change « from 1,2, 3] to (1, 7,3] nd) ss one oad Basic Arithmetic and Functions 3+4, 7e4,2°6,8/3 multiply add, subtractand divide EE Mutipy every element of = by ‘Ado 2 to every element of 2 Element-wise adsition of two vectors x and y Product of 2 matrix and vector Product of two matrices Hloment-wise procuct of two matrices Square matrix tothe third poner Every element of Ato the third power (Compute the cosine of every cloment of A Compute the absolute values of every element of Transpose of A Compute the inverse of A Compute the determinant of A Compute the eigenvalues of A Getthe size of A The 2" t0 the 2 elements of x ‘The 2% to the last elements of = very tite element of «from the fst to last Gt the 5" row oF A Get the 5" colurin of Got the first to third elaments in the 5 vom Plotting ploton,y) v7 omeute 5” sart(s) Compute v5 Vostogtx.¥) 1os(3) Compute in) Yogi9(169) ‘Compute log(100) senilogx(x, abs(-5) Compute | — 5) senilogy(x, sin(5+pi/3) Compute sin(5/3) axis equal Hens ene tite('a Th Mabel Ylabel'y U Aegend Foo zeros(12, 5) Wake a 12x mavin of zeros ata ones(12, 5) Nake a 12x matin of ones hold on eves) uake a5 «5 idetty matrix rae eye(12, 5) ake 812 5 ideriy mat Linspace(1.4, 6.3, 1604) ‘make a vector vith 1004 ele~ iments evenly spaced between Plat y versus 2 (must be the same length) Plat y versus + on 8 loglog seale (both axes havea logarithmic sale) » Plot y versus x with x on alog scale y Plt y versus with y ona log scale Force the = and y axes to be scaled equally tte") ‘Add a tide to the plot abel’) ‘dd a label tothe » axis abel’) ‘Aad label to the y axis *) tbar") {abet 2 curves forte plot ‘Add a grid to te plot Mulinle plts on single figure Start new plot aoe eel ED Logspace(1.4, 6.3, 1604) Make a vector with 1004 ele ainebaetieron iments where the log of the inf Infinity specing is evenly increasing be- rrealmax Largest positive loating-seint number 1.7077 108 een aa realmin Smallest positive foating-point number 22251 Row vector of 7, 8... 14, 15 10-8 Steven € Thornton “Steventhorntonsca Updated: December 1, 2076 MATLAB CHEAT SHEET for k= 1 3500005 end Tce k winite’k ¢ 7 % Assign a the festira is value of 3 caus 5 Test if a is equal to 19 Test if a is less than 11 Test if a 4s not aqat to 4 Test if a as greater than 1 AND 40 § Test ifa is greater than 108 % not equal to 10 Cirinneecnens if ase 9 Greater thon 10°; ts5; eis9C else! vp S190C elaher condition wet"); function output = addtunbers(x, y) y outputn Wi addtnbers(12, -3) : f= a(x) sinl42) M5 Hoif2) 9795, FEC-pI/2,, 8 pia) 25%6H98 wan 0.0795 xc Linpace(-doi, deri 1000 a singe Yt costs Plots, yi, “k-"); § Plot sin(x) 95 a black Line hod of S Now we can add another curve POUR, ¥2, “#-")} & PLOE coscx) a5 9 Ped Line aris (epi, epi 21.5, 2.50) x Add 4 tile Uete(' plot of cos(x) and Sint) Ds Add 2 Lesena De plot of cos) and sin) re — feat a8 Steven € Thornton “teventhorntonca Updated: December 1, 2076

You might also like