lOMoARcPSD|31072203 Matlab Onramp notes MATLAB and Simulink for Research in Industry (Coventry University) Studocu is not sponsored or endorsed by any college or university Downloaded by Prince Suman (pssuman2004@gmail.com) lOMoARcPSD|31072203 Matlab Matlab First 30 course wk 1 Simulink a Intro IIpt mins useless Commands just talking about how he designed and designprocess Simulink is apart Matlab Matlab is software of oriented standard a library consisting functions of package of Matlab allows you to code through the library with quick setsofinputs Simuline is a graphically based software Consists of a library blocks used to calculate mathsmodule or of produce Have response in the form a a look at reaomended Week 2 Matlab of a graph 1 2 Programming in Matlab books 20 Part Introductions Input Commands COMMANDS Clear r clears workspace Save Save workspace tofile filename Load filename loads variablesfromsavedfire entername variable Displayscontents Variables of of Downloaded by Prince Suman (pssuman2004@gmail.com) lOMoARcPSD|31072203 q of pays Ackers Bonnard window IT pi sqrt formatlong to display more decimalpointraves switchbackto defaultdisplay format shot CLC 3 I when B the standard set up bag the Command window workspace start Matlab you workspaces current holder All their Gommands outputs together canbeorganised by brewing alive script in MATLAB editor by Enter the commands clinching new live script intothe grey codebox clicktextmode to annotate commands This lets you run button that multiple commands evaluates atonceby all commands inorder clicking the run broken into sections Gectionbreakbutton letting you run justthat section Maximise the MittaB editor or select layout button to use fivescript The script can be with command window 4.1 All maths variables are arrays Coach numeric variables contain murine I Eiti Downloaded by Prince Suman (pssuman2004@gmail.com) lOMoARcPSD|31072203 Arrays can be created with Squee brackets iegfx BS o.sc 3 separating the numbers with aspace or comma it creates a rowrector Column vectors are created with semi lolonsfnbyD.egfx fi.SI ax s 3 8 0 will shorten the input numbers Eg if 5 8 ay 5678 Using f Thespacing is automatically setto onebutcanbealtered Eg yes 20.8 GETS to 7189 b axe I 3 13 JE 3.4 12.13 2 3 213 Boxe 3,47411113 If the ofelements wanted in avectoris known use the finspace function binspacerfirst led 00400.2so asoo Jelements 2Gtinspace last r also to Arowvector canbe transposed into a column vector using an apostate f l a Cg I 3 axel 23 simplified x rand x de rond fy iz Or you can use Il 2 1 to see x Es 3 creates a randomarrayof 2 by 2 l instafund yby 2 E ones see if i 5.1 Every variable in MATIAS is an array Indexing referringto elementsin an array This is howyouextract Modify arrays The position of a valve in thearray is calledits index The index canbe used to extractparticular values 8 9 10 I 2 3 y S Z 7 Dt x 213161 910 Is I 3 I 7 l Il 8 x Teffersetothe 3rd position which can easily be chargedby di 37 It or you can extract x 2 47 A B l 9 orangeof valves with a colon Downloaded by Prince Suman (pssuman2004@gmail.com) lOMoARcPSD|31072203 Seg SC Nr D requires youto specify2positions you wantto extaract Anwhole row or column use a colon as an index This way the colon stands for all KCI meansfirstrow son's 3 To or andall columns A matrix rowholumn If 34 18 xe.io REMEMBER MATRIX INDEXING Is and vectors only need 1 index end is It can acrow CoD Matlab keyword used to reference the lastdemerit be used as an index This can also be usedwith a arithmic tofind the second last fend fend 2 y A single index valvecanbe demerit of 5th lasted used to reference vectorelements the3rdelementof vector v wher vis eitherardorld Asinglerangeofindexvaluescanbeusedtoreference asubsetofrectordennisreg servo add the returns asunset redorrContaining elements from 3to end of Cgi term returns b You can addtogether any 2arrays ofthe same size The Marinum raveof avatarcanbe determined using the malfunction Max MaxGO e When multiplying matrix do not use to perform erementwise multiplication elements ofthis gravy filth sizedarrays use Thisallows ya thehorresponding you multiply Downloaded by Prince Suman (pssuman2004@gmail.com) lOMoARcPSD|31072203 The size Variable containing toanarray toproduce canbe applied function the array size Using squarebrackets Escrow I cold Size S a singleoutpet size 00 for morethanone output canbe obtained The Maxvalue ofavectorandits corresponding index valve can bedetermined usingthe Max function Thefirstoutfitfromthe matfund isthemax value An input rector The second wall isthe indet value of GcMax ida fit MaxGO 8 you comeacross afunction you dontknow you can use thematlab documentation by choking ke helpbutton andsearching the function inthe browser When q plotting Twovectors using the ofthe samelength pot function protocol The plot function additional argument thatallows you stole using differentsymbolsin dashedlines 8 o can be plotted against eachother to singlequotes colour linestyle manner specify the where r red plotGc y r o acirdeab a marker To plot oneline ontopofanother usethe hold on command addandherline while you When the holdon stateis on plotswill previous command acceptan III continueto toholdke the sameaxis go on Downloaded by Prince Suman (pssuman2004@gmail.com) lOMoARcPSD|31072203 her he Toreturn l i i g s todefault plotbehaviourwhere eachplotgetsitsownaxis wehold n np n off When threatorvalves the axisandautomat yougot asinglenectarby itself Matiabuses for y assigns the x axis datatorange In Theplotfunction accepts optional additionalinputs consisting ofaproperlytamedassociatedrive width 5 wherelinewidth is thicknessand 5 is thickness value plotCyfline plotters ro i'linewidth ANNOTATING PLOTS labels canbeaddedtoplotsusingplotannotation functionssuchas title Theinputtocheese functions is a string glabelflubdd stringsareenclosedin doublequotes legendTa b I titteffottitle I 10 Electricity Usage project In this project youwill got electricity usage for various economicsectors Cresidentid commercial kindustrich 10.2 AUDIO FREQ Project In this projectyouwill analyzethefrequency latentofan organplaying the C chord CC 2.61 6th 329.6142 6 392.0HI N IMPORTING DATA The current folder browser lets you on your computer If explore any files youhave a Matlab select you wantto import file into Downloaded by Prince Suman (pssuman2004@gmail.com) lOMoARcPSD|31072203 e l won mp C p w r y the file click import data on doubleclickEDO DC on a mat file will open itin nub DC a jpeg will open itas f y f arrayofpixel values DC on a txt or Csvrspreadsheetgives alotof options on how to store theinfo on matlab so the importtool opensand a preview thedata is shown The data that will be of a numeric willbe highligted inblue any missind datain orange and win by default be replacedwit Nan fNatalimarl default By the importtool will import this as a table but otheroptions are available under output type stable bivector NumericMatrix string A table allows all the data to be imported array all array into 1variable in the workspace The import fool automatically chooses an appropriate datatape foreachof thevariables inthe table butyou the outputvariable can change it ifneed be The default name imported comes the from file name spreadsheet to Its Common contain headers for for thefirst foryour columns row ofyour tool The import that and uses them as thetablevariablesones When you click the import selection button Matlab importsthedataand createsthe sees variable in the matlab workspace To extract a variable fromthe table you can use eg a data VariableName dotrotation you working with table you might wantto keep related data If theresult together Instead are calculation to doesn't exist a ofcreating separatevariables you can assign table dataHeightMetres data HeightYards a 0.944 if of a Metres dataHeight willcreate anewVariables inketablewiththe rare HeightMetres MATLAB Downloaded by Prince Suman (pssuman2004@gmail.com) lOMoARcPSD|31072203 l w are anew ar Ir ke ab herane w ab g Youcan interactwith a tableby clicking on it intheoutputpaneofalinescript Forexample tableusingone itsvariables Onceyouarehappywithyourtable canmakethe youconsort a of you changes permenantby updatingthecode in yourscript Dot rotation is used toextractfake variables Toextractrows youcanuse NewTable Name regular array indexing OldTableNamed 3 To extractthefirst3rows rotatable 12 Logical INDEXING Rational operators suchas 74 and performcomparisons between2rones foracomparison forequality orinequality iseither Iftrue or 0Jase Theoutcome Youcan compare avector ormatrixto asinglescalar rave Theresultis a logicalarray ofthesamesize astheoriginal array using rational operators is in You can use dogia array ab a index inwhichcase Matlab extractsthe rag array elements where theindex is true Eg Toextend all theelementsinVI than 6 V Not 60 it beb greater Youcanalso uselogicalindexing withtwodifferentvectors V Sampleon 67 V 13 ifyouwishto replaceall Youcanuselogicalindexingtoreassignvaluesin anarray Forexample array fallowing Syntax ache 7997 areequalto 999with 1 usethe odthat Youcan thelogical operators and use Tofind values Tofind values Hl and or lessthan 4 andgreaterthan2 use 6 than greater or 2 use Ii lessthan x valvesinthe 1 A VIGIL47 0 tocombine logical comparisons x v1Gk4 v120 it fit 6 I AD Downloaded by Prince Suman (pssuman2004@gmail.com) lOMoARcPSD|31072203 J 13 I g Programing scripts by default calculatefrombeginning toend IIII What if wantedtoseethe softfoe if I waspositive Thecode you only it is a is positive andbehave accordingly end Irresgaroo Now when x is positive this conditionistrueandallthecode xsg xn2 Willberun X is can determine tug Ifstatement thethecodeisfalse and it skips to theendstatement The control theflowoftheprogramme Anoter is the is one way to flocks thatexecutejustoneseatingcodefrom2optionsormore insted skipping withoutcopypasternodigy of you wantto repeat a setofcommands common loop is a farloopthat uses the you canuse aloop Themost If If If for keyword followed bythe desired repeated codefollowedby read thebroody codeinthe loopwill be repeated multiple times it's a simplecode a loop probably isn't needed and you can use Matlab natural array capability i without a loop for cases more complicated If for100ps giveyou away torepeat a setoftasks acrosscorrectionsofdata The bodyof an if blockis only executed thecondition is true if Use tocheckforequality items Is The Kisei keywordcanbeusedafter includemultipleretseifblocks x rand if oeio.SI Condition end if toddy toaddmore conditions youcan when this codeis on theloopbody willbeexecuted for Downloaded by Prince Suman (pssuman2004@gmail.com) counter poop I 3 g lOMoARcPSD|31072203 cod three times I 3 run I al f as the loopcounter p Progressesthroughthevoves y 0 end 0,280 dtsPrc T fwpvwenttolooponeraveo.org unknown length you can length function instead 14 I for idoc tilengthrvector.name Stellar MOTION PROJECT Downloaded by Prince Suman (pssuman2004@gmail.com) body use the