10 views

Uploaded by Azhar Mahmood

- SISTEMAS ELECTRICOS DE POTENCIA.docx
- Robotics Toolbox
- c_questions1
- Image Processing Toolbox
- Usersguide 1 Intro
- Piyush Soni Resume
- Question 1
- User DefinedFunctionRev0.2
- MatlabTutorial2.pdf
- Matlab tutorial: Function M-files
- Schedules
- HW1_ENED1090_AUTUMN_2014
- Train Adaptive Neuro-Fuzzy Inference Systems - MATLAB & Simulink
- Matlab-Tutorial
- DSPLABMANUL
- Unit 5
- Content Monitoring Of music
- Learning C.doc
- Poster Final2
- Parameters and Arrays

You are on page 1of 5

Matlab Primer

This short Matlab primer is adapted from a lecture in Introduction to EPR Methods and Instrumentation at Miami University and gives a very basic overview to get the user started with the package. Really the only thing needed to operate the !ector "iagram #imulation Package is the section on data entry in Matlab but the other information might prove useful for someone $ust getting started and using Matlab. (etting )el* in Matlab %ortunately Matlab is a very popular piece of software and as such there&s no shortage of places to obtain help. I have found the following book to be e'tremely helpful in learning the ins and outs. Mastering Matlab ( I#)*+ ,-.-/.,-0In addition there is e'tensive online documentation from Math1orks the creators of Matlab+ http+22www.mathworks.com2access2helpdesk2help2helpdesk.html There is a user forum where you can post 3uestions+ http+22www.mathworks.com2matlabcentral2newsreader2 If all else fails $ust 4oogle 5Matlab bla bla bla6. I have never been unable to figure something out that I wanted to get accomplished by going through these channels. +ntroduction Matlab is a technical computing platform that consists of the mathematical functions programing tools and figure generators. Think of it as an operating system that runs within your main 7# that has all of the math8based things that you need. The command line interface uses mostly the same commands as 9inu'2Uni'2Mac7# terminal windows. The main Matlab Interface consists of+ :ommand 1indow ; like a "7# prompt or terminal window for issuing commands. Editor 1indow ; a te't file editor like *otepad that can be used to generate functions programs input files or any other te't based files. :ommand <istory 1indow ; provides a list of previously issued commands with time stamps. :urrent "irectory 1indow; the current directory in which Matlab will save a file or retrieve a file without an entire path to the file =i.e. in this directory Matlab will recogni>e test.t't without having to give c+2documents2user2desktop2test.t't?.

1orkspace 1indow ; lists all of the variables array matrices vectors structures etc. that are in the working memory and gives some info about them. Each 1indow can be moved around placed into a side tab or a top tab and popped in or out of the Matlab control window. Data Mani*ulation in Matlab In Matlab there are four main types of data+ numbers arrays strings and structures. *umbers ; self e'planatory use the following method to store a number to a variable+ >> x = 3 x= 3 @rrays ; @rrays are vectors or matrices they can be entered in the following way+ >> A = [1 2;3 4] A= 1 3 2 4

#trings ; #trings are pieces of data that Matlab will treat as te't. #trings can be entered as follows+ >> samplestring = 'This is text in Matlab.' samplestring = This is text in Matlab. #tructures ; #tructures can be thought of as a package that contains data of various types. The format for structures is 5nameofthestructure.field6. Aou can put whatever type of data within each field that you want and can recall it by either using $ust the structure name =this will display all of the fields in the structure? or by referencing a particular field directly. >> sample.Name = 'R b M!"arri!#' sample = Name$ 'R b M!"arri!#'

>> sample.Age = 34 sample = Name$ 'R b M!"arri!#' Age$ 32 >> sample.%a& rite'matrix = [( 1)2;*1)2 (] sample = Name$ 'R b M!"arri!#' Age$ 32 %a& rite'matrix$ [2x2 + ,ble] >> sample sample = Name$ 'R b M!"arri!#' Age$ 32 %a& rite'matrix$ [2x2 + ,ble] >> sample.%a& rite'matrix ans = ( (.-((( *(.-((( ( Reading in Text Data 7ne of the things that you will often need to do is read in data. If you have a te't file containing data you can use a built in Matlab function called te'tread. >> [x+ata .+ata] = textrea+/'sample.txt'0'1% 1%'0'hea+erlines'012 te'tread re3uires first a filename second the type of data in each column of the te't file =in this case floating point numbers? and third the number of headerlines containing labels and such that need to be skipped. Plotting Data in Matlab 7nce you have some data read into arrays it would be nice to be able to plot it. %ortunately this is really easy in Matlab using the plot function.

>> pl t/x+ata0.+ata2 If you have more than one pieces of data you want to plot $ust tack them on >> pl t/x+ata10.+ata10x+ata20.+ata22 *ow lets assume that you have some mathematical function that you want to plot =for e'ample lets assume that you want to generate a sine function?. The first step is to generate an array that will serve as the ' values for the function. The best way to do this is to use the linspace function in Matlab. >> x = linspa!e/*1(01(02(12 The first value is the start point the second the end point and the third is the number of points in between. *ow we can create an array that is the sine of each of the points in the first array. >> . = sin/x2 *ow we simply plot it. >> pl t/x0.2 Saving data in Matlab 7ften you will want to take data generated or manipulated in Matlab and save an @#:II file. This is done using the save command. The easiest way to do this is to create a single array containing all of the data and then use that for the te't file. [+ata] = [x+ata0.+ata] sa&e 'sample.txt' +ata *as!ii ,-ing the Editor to +--ue !ommandUsing the command line is fine for some things but it can be pretty inconvenient when dealing with much larges sets of commands or scripts that you&ve written. The easiest way to create large sets of commands and scripts and keep a record of what you have done is to use the editor window. In the editor window you can create a te't file that can be e'ecuted in a line by line manner. #hown here is a sample t't file =files saved in Matlab carry the 5.m6 e'tension. 11 A 3ample M*%ile that 4enerates a 5l t % the 3ine 6,n!ti n !lear all; 1 this ! mman+ !lears all &ariable an+ s,!h

11 4enerate the Arra.s x = linspa!e/*1(01(02(12; 1 "reates an arra. % x &al,es . = sin/x2; 1 !reates an arra. % . &al,es 11 5l t the 7ata pl t/x0.2; 1 !reates a pl t % the sin %,n!ti n %r m the t8 arra.s 11 3a&e the 7ata [+ata] = [x0.] 1 !reates a + ,ble arra. 8ith the t8 x an+ . &e!t rs sa&e '+ata.txt' +ata *as!ii 1 sa&es an as!ii %ile % the t8 arra.s Aou probably notice the e'tensive use of the 5B6 symbol. In Matlab anything after a B sign in a line is ignored. This allows one to make comments that are useful when going back to something after a long period of time. In addition recent versions of Matlab you can use 5BB6 to separate that part of the file into a cell. The cell can be e'ecuted separately from the rest . 7nce you have everything set and ready to e'ecute you can select all of the te't and press the %C key =in 1indows?. This will e'ecute all of the commands. This way of issuing commands is convenient as it lets you save a file for each set of commands.

- SISTEMAS ELECTRICOS DE POTENCIA.docxUploaded bymarkitobp
- Robotics ToolboxUploaded byJose De Jesus Moya
- c_questions1Uploaded byKrishna Prasad
- Image Processing ToolboxUploaded byn4arjun123
- Usersguide 1 IntroUploaded byGabrielIgnacioFuentealbaUmanzor
- Piyush Soni ResumeUploaded byravi
- Question 1Uploaded bySantanu Debnath
- User DefinedFunctionRev0.2Uploaded byACERGY
- MatlabTutorial2.pdfUploaded byIloaie Maria Georgeta
- Matlab tutorial: Function M-filesUploaded bySara
- SchedulesUploaded bysivasaipranavj
- HW1_ENED1090_AUTUMN_2014Uploaded byBill Williams
- Train Adaptive Neuro-Fuzzy Inference Systems - MATLAB & SimulinkUploaded byMiljan Kovacevic
- Matlab-TutorialUploaded bywsrendy
- DSPLABMANULUploaded byRafi Ullah
- Unit 5Uploaded byVinod Deenathayalan
- Content Monitoring Of musicUploaded byKomalFatima
- Learning C.docUploaded bysrinivasknaidu
- Poster Final2Uploaded byMiguel Almas
- Parameters and ArraysUploaded byAgrippa Mungazi
- MS Excel (Advanced Functions)Uploaded bySuresh Kumar
- matlab pra biologosUploaded byPatrick Lobato
- Analysis and Implementation of a Data Pre-processing SystemUploaded byEditor IJRITCC
- ANPR PowerPointUploaded byThoque Isma'il
- DOC-58962Uploaded byjustforregister
- Cps Module 3Uploaded byRadhika Ajadka
- MBSD0 Lab ManualUploaded byRafael Andrade Moreira
- MATLABUploaded byShailin Sequeira
- C MaterialUploaded byVarun Yadav
- Problem Set on Strings and ArraysUploaded bySatyanandaram Nandigam

- CAAMS_02Uploaded byAzhar Mahmood
- Chapter3-Imaging With Terahertz WavesUploaded byAzhar Mahmood
- Lecture 23Uploaded byAzhar Mahmood
- optical_properties.pdfUploaded byAzhar Mahmood
- Sprtheory EnglishUploaded bys1hahriar
- Nature-Plasmonic Nanoresonators for High-resolution Colour Fi Ltering and Spectral ImagingUploaded byAzhar Mahmood
- nphys287Uploaded byAzhar Mahmood
- Syllabus MSc Math ProgrammeUploaded byAzhar Mahmood
- Cgaleriu k p Theory of Semocond Nanostructures (Worcester)Uploaded byИгорь Петров
- Biegel B Wigner Function Simulation of Intrinsic Oscillations Hysteresis and Bistability in Resonant Tunneling StructuresUploaded byAzhar Mahmood
- Zorn (1)Uploaded byAzhar Mahmood
- phys208-2005.03.16.pdfUploaded byAzhar Mahmood
- 3-Simulation of Quantum Transport in Quantum Devices With Spatially Varying Effective MassUploaded byAzhar Mahmood
- Syllabus MSc Math Programme.1 2Uploaded byAzhar Mahmood
- 04383328.pdfUploaded byAzhar Mahmood
- p879_1.pdfUploaded byAzhar Mahmood
- Thesis_Electron-Hole.pdfUploaded byAzhar Mahmood
- chap01Slide.pdfUploaded byAzhar Mahmood
- chap01Slide.pdfUploaded byAzhar Mahmood
- PhysRevB.36.5887.pdfUploaded byAzhar Mahmood
- chap04Slide.pdfUploaded byAzhar Mahmood
- Thesis-Resonant tunnelling of Wannier-Stark states.pdfUploaded byAzhar Mahmood
- e042111.pdfUploaded byAzhar Mahmood
- e195304.pdfUploaded byAzhar Mahmood
- e195304.pdfUploaded byAzhar Mahmood
- 01073171.pdfUploaded byAzhar Mahmood
- chm4m4Note.pdfUploaded byAzhar Mahmood
- 05_Barrett_Hardy_Kent-No_Signaling_and_Quantum_Key_Distribution.pdfUploaded byAzhar Mahmood
- 1103.0872.pdfUploaded byAzhar Mahmood

- Embedded Linux Kernel and DriversUploaded bynagendra_tes_dst
- Umair - Software EngineerUploaded byUmair Asghar
- QwertyUploaded bysir
- 2011.ijnm1Uploaded bybhvijaykumarn
- Chapter 1 CompleteUploaded byraymond
- PPT-2 Intro to CompUploaded byJawar Singh
- LANUploaded byAmirul Ihsan
- Java_LAB_02_updated.pdfUploaded byVishal Patil
- 06 PE Architecture MalagaUploaded byMarco Garcia
- Linux 1Uploaded byKasun Gayashan Randeniya
- tr40asr9kbookUploaded bySanta Maria
- 245 Cisco Low Latency CollateralUploaded bysrotenstein3114
- Dynamic Object ModelUploaded byKokila Naresh
- 05 InterruptsUploaded byarunmcbe23
- SCL siemensUploaded byBenedict Jo
- Test 2Uploaded bydmracc17
- 5b-AVR-Timer(16-bit).pdfUploaded byzohaibshabir
- Tri CoreUploaded byimensassi
- Sap Library Guide UnixUploaded bymanishkumar1979
- 4x1w LED Inground Light Technical DatasUploaded byVictor Ciprian
- techinical vlsiUploaded byrkguptha_514369372
- Agile Example HealthcareUploaded byTodd Schavey
- IC_LMC555Uploaded byJeremy Obriot
- Dino Dai Zovi: Mac OS XploitationUploaded byHao Lian
- ChandanaUploaded bychandana
- TRAWMManualUploaded byLeonhartv8
- 0.18um Modular Triple Self-Aligned Embedded Split-Gate Flash MemoryUploaded byYohanes Erwin
- Start of report acknowledgement ,abstract etcUploaded byGaurav Kumar
- Mitsubishi - A2ncpuUploaded bytaufiq4923
- Drivers ListUploaded byahmed_g