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

Matlab Basic Functions

Matlab Basic Functions

Uploaded by

Sujay S
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
64 views

Matlab Basic Functions

Matlab Basic Functions

Uploaded by

Sujay S
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
@A MathWorks: MATLAB® Basic Functions Reference ele Cle command window Define variable a with valve 5 help fun Display inline help for fun doc fun ‘Open documentation for fun Toad(“filenane™ "vars oad voriables from -mat He Ulisport(filenane) ‘Open interactive impor tool ve("Filename®y vars! Save voriabler fo file clear item Remove ms from workspace exanplescripe Run the script fle named examplescript format style ‘Set ouput dieplay format ver Get lst of inealed toolboxes tie, tee ‘Stat! ond sop timer cesne ‘Abort the eutentcalevltion ee Operators and Special Characters ‘Matrix math operations ‘Array muliplication and division nite operations) Matrix and array power ae G2 ase Ae a23 Define A os @ 2x3 matrix “space” separates columns "For new line separates rows Coneaierole arrays horizonally Coneatenate arays vertically Change ath element of x10 7 aa.) ‘Change Afi) 10 5 eo) ‘Get Sth 10th elements of x (Bend) ‘Get every 2nd element of x [Ist fo las xe in elements greater than & xGessi0)= ‘Change elements ving condition aw Get Ath row of A Ae, 3) (Get Sed column of A ALG, 25) ‘Get 2nd fo Sih element in 6h row of A AGB TAG? DD ‘Swap the Ist and 7th column = [ool 42, at] with eens wae ‘Creale regularly spaced vector wih spacing de Left division or line transpose 1 eplimization ‘Normal and complex conjugate Linspace(a.b in) ‘Create vector of n equally spaced valves Togepace(s.b.n) ‘Create vector of logerthmicely spoced values Tibia ie a eteing™ wtrl + stra Definition ofa sting ‘Append sings Seen ==) =) & >) Ss) >= | Relational operators | [rerostm.n {Creale m xn matrix of zer08 wel a wer Tole operaions | tm Create mx n matrix of ones IAND, NOT, OR, KOR) even) Create @ nx identity max ‘Suppress ouput display Bediag=) ‘Create diagonal matrix from vector - ‘Connect lines (vith break) xediag(a) {Get diagonal elemen's of matix + Description Comment eshgrid(y) Creaie 2D and 3D grids ‘welio" Defintion ofa character vector Fand(a,n), andi ‘Create vnifornly distributed random umber: of inte randn(sn) ‘Create normally distrbuted random umber: (ero ced ane ‘Most recent answer Add Imaginery unt PE io3.141592654, reals) Real part of complex number a Imaginary ont inag(=) Imaginary part of complex number Yaw, man Not e number fie, division by zoe] angle) Phare ongle in radians Ent, int Tafinty cong Elomentwise complex conjugate ops Hating pain relative accuracy iereal(2) Determine whether array is rel A&A MathWorks: as nt), asin Sine ond inverse argument in radians) lot (x,y, Linespec) Plot y vs x Tenabiy ated Sov end ven ergnertin arg] | U3 ioeesinarinsh inh), aeinh Hyperbole sine and inverse (rin Markos Leeetyle, maven, nd ests eee oe | ree Tosa is gc bs ous mere Ales ff Wr Sie ear n+ | UtPidine wih nates abs(x) Absolvte valve of x, complex magnitude Satlecrieie") Add plot fitle oan Acie Teqenatiae ae) [nl egnd ar sgrt(x), nthroot(x,n) | Square root, real nth root of real numbers x/y/zlabel("label") Add x/y/z xis label = ———e Thivcckattickavec) | Setar ay une resto oad ieguibm ihe 2 and mayen | | ply/sickiabeistianeiay| Ge oro vee ae ob eterna Romain Thfecikaosielansie) | Yoon ys eel san) win Celery ove wean d Sarin ro waists) eels vee | Sea td a Selib Finy Beer | pom rd ak a exci) nadie 7 taunt ser doin ape gris oloft Show oad wo eee Tet be cmv cao Sorhomt capstan Cre sn led potion ‘table(vart,...,vasi) ‘Create table from deta in variables eiledlayout(in.n) core pris tthe | Geum nemo Fase Gaile on fe fee Coie gre window sereyaeanio Cant a aye set 5 Ga coal lgoe, ga aE Fone tated dats fon clove oe Con ore igre rors alsa Cea ew wih ecied | [ eae aE Sis nen as Heowspecrreniwn | Sotael Succ rs Tenia Reet BT Connon Pt pen a eens repent ‘categorical (a) Creale a calegerical ervey a a ron, orcopsunneny | Pint snnary a ble R Sein, Fh Tan ew cmon oe ee ae & (MW aa Tasks (Live Editor) ee = = Live Editor tasks are apps tho! ean be added fo a lve scrip 0 interactively perform a specific set of operations. Tasks represen’ a series of MATLAB ‘commands. To vee the commands that he tsk runs, show the generated code ‘Common asks available from the Live Edt tab on the desktop tooltip + Cleon Missing Dato + Clean Outer + Find Change Point + Find Local Exroma Flot Gallery: mathworks com/product/malab/plat gale + Remove Tends + Smooth Data " ° poy Se ee at @A MathWorks: oes pen Functions fxero(fon,x0) Roat of nonlinear function jeript fle. Function files must have the § sane name as the 1st function fonction cavg = cumavg(x) multiple args. possible cavgzcunun(vec)./(:tength(vee))? ‘Eminsearch(fan x0) Find minimum of function ‘Eninbad (fn x1, x2) Find minim of fam in el x2] eG), Leet Feast Fourier ransform and it inverse ‘Anonymous Functions Integration and Differentiation © defined via function handles fun = @(x)_cos(x.n2)./abs (3): integrailé.a,b) ‘Numerical integration {enalagovs functions for 2D and 30) Af, elseif Conditions erape te) Trapezoid numerical integration Control Structures aire Diferences and epproximate derivatives geedient) Numerical gradient Af nao aéep('n sealer 10") elseié nce20 disp(-n between 10 and 20") Curl OK BUM) Curl and angular velocity ivergence(k,.-.¥) Compute divergence of vector fle ‘edets (ode tepan.vo) Solve system of nonsiff ODEs disp(inagative one") case (0,2,2,3) + check four cases together isp("intager between 0 and 3°) otherwi: diep("integer value outeide interval [-1,31") fend control structures terminate with end Pdevai (n,xmesh, susol xa) else ‘étepira larger then 20°) ‘edeise(ode,tepany0) | Solve wystem of stiff ODE ‘Sch Cave deval(eol,») Evaluate sltion of diferentiel equetion = Enput(Enter an integer! ")y ‘Paope (a pde, ic, Solve 1D partial differential equation switch n ‘be xm,t8) case “1 Interpolatenumerie PDE soution Interpolation and Polynomials Forloop interpltew xa) 1D interpolation {enalagous for 2D and 30) © loop specific number of times, and keep % track of each iteration with an incrementing % index variable for = 1:3 Aisp(‘cool") end control structures terminate with end Pehiptew.a) Piecewise cubic Hermite palynomial Interpolation spline twa) Cubic spline date interpolation ppvailep xa) Evaluate piecewite polynomial smkpp (breaks coefts) Make piecewise polynomial While-Loop ‘SBRKPPIPP Extract piecewise polynomial details % loops as long ae @ condition remains true asa pFactorial = 1; while nFactorial < 14100 nent: nFactorial = nFactorial + n: fend § control structures terminate with end poly) Polynomial with specified root x ‘polyeig(A0,A1,..-/AP) Eigenvalues for polynomial eigenvalue problem polyeittea) Polynomial curve fiting Further programming/contol commands Feaiaue(al Poriel facion expanion/decomposton roots tp) Pelynomil rots polyvalip Evaluate poly po point x olvinee) Pelyronialineprtion polvaer(e) Pelyromildifereniaton break Terminate execution of for of whileoap continue Pass contralto the next iteration ofa loop try, eaten mathworks.com/help/matlab <@ MathWorks: ‘Accoerting the pace of engineering and science Matrices and Arrays Deseri ive Statistics Bengeniad Length of largest array dimension sun(), prod Sum or produc long colynns) “ize ‘Array dimensions ax(R), Bis, Bounds | Lorgest ond smelt element mune ‘Number of elamens in oray ean), sedian, mode | Silsieal operations =) Sor erayeleenis sea, ver Stndard devin ond variance sortrows@) Sor rows of eray or tobe ‘oveun(A,A), movpred, | Moving saical functions movaax, movmin, i= length of moving window nig lip order of elements in arr “e " Pe) Fip order of ay movnean, novmedian, ‘squeeze Remove dimensions of length 1 ovata, sowear Feshapetavez) | Reshape array cunsua(), cumpred, | Cumulative sainical hnctons repmat(A,n) Repeat copies of array comme, cummin any), at Check ifanyall elements are nonzero [_sncorndareta) __|_ Smooth nety data ny Naber ronsvoavey doves istcounes 00 elevate histogram bin counts on Need eh eee sea corrcoet(h), cow Correlation coofcons, coverince xeore(ea), cor Cron -orelaion, ers-covaance ‘neo Algebra aermalize(a) Normalize data datendic) Remove polynomial wend anki ork of matic om ork of matr Teoutiierta) erace(n) Sum of dogonal element of marx ase) Determinant of marx poly(A) ‘Character polynomial of matte Sypatiets Os sigiA), cigs Eigenvalues and vectors of matrix (subse!) xe syns * YE Declare symbelic variable Envi), Pinw Inverse and pioudo inverse of mati wery mee Define «symbole eavation orn ‘Nowm of vecor or mati solve eqne ware) Solve symbolic expresion forveriabe expat), logs | Matrix exponentl and logarithm = = ' tube (eape var wall tive variable exprension ez00s(a8) ‘ross produe = eee soc.) Det ped [-ssesnstenee) __] fered boc naresien__] ‘kxon(A,B) Kronecker tensor product | simplityexp) TT e > |_Fectorize symbols exprenion _| = ere Binplity (exp Simpy symbole expression orth(a) Orthonermal basis for matrix range: {hake asempien for veriotle ee ° 7 Show estumption for 5 Lower end upper riongular pat of max yakole sheer Linsolve(A,B) Solve linear system of the form AX=B Eplot(expe), feontour, Plotting functions for Tequinnora(A.B) | leostiqvores soliton 1 Ineor equation faurt, fear, timplicit | symbole expressions GOD, 3, enol | Mak decomposition: ite (expe vara) Diferentie symbole exprenion 7) ‘Singular valve deconpostion ‘deolve(deqn, cond) Sole differential gevaiaB) ‘Generalized SVD |__| eqvetion symbolically _| Fee) Reduced row echelon form of matrix |_Antlexprivarsta, PI) | Integrate symbole expression _| taylor (fun,va £0) Taylor expansion of fneon *requires Symbolic Math Toolbox mathworks.com/help/matlab ©2001 Th ios, he MATA ier poder ond sans ay Sms pred acento he ahs, ne So maha con/nedmat oo ford rademats

You might also like