Successfully reported this slideshow.
Upcoming SlideShare
×

# Matlab Introduction

The frame work that I used for my Introduction to Matlab hour long course. Most of the instruction took place on a live Matlab screen, but this provided the framework

• Full Name
Comment goes here.

Are you sure you want to Yes No

### Matlab Introduction

1. 1. Matlab Introduction Tim Brunner Daniel Moore
2. 2. What is Matlab? <ul><li>MAT rix LAB oratory </li></ul><ul><ul><li>Computing environment and programming language allowing for powerful numerical / image analysis and manipulation </li></ul></ul><ul><ul><li>basic data element is an array that does not require dimensioning </li></ul></ul><ul><ul><li>It allows you to solve many technical computing problems, especially those with matrix and vector formulations, fairly quickly </li></ul></ul>
3. 3. Why use Matlab? <ul><li>Huge library of mathematical functions and algorithms </li></ul><ul><li>Fast implementation of vector/matrix operations </li></ul><ul><li>Powerful visualizations (when used properly) </li></ul>
4. 4. Sample Matlab Screen Command Window: Insert Matlab statements at the prompt Command History Current Directory Script Editor
5. 5. Useful documentation (Seriously) For documentation on a particular command just type `doc <command>` at the prompt … Or use the help menu bar
6. 6. Matrix and Vector Algebra <ul><li>MATLAB is based on matrix and vector algebra </li></ul><ul><ul><li>Even scalars are treated as 1x1 matrices </li></ul></ul><ul><li>This means you have to be careful when using operators on data </li></ul><ul><li>Rule of thumb: functions (like sin(), cos(), etc.) act on each individual element; operators perform matrix operations </li></ul><ul><li>Use dot operator notation to operate on individual elements (.*, ./) </li></ul>
7. 7. Graphing <ul><li>Matlab can make a large variety of graphs </li></ul><ul><li>User has a large degree of control over what can appear on the graph </li></ul><ul><li>Graph can be made from the Matlab command line or by using the plot tools GUI </li></ul><ul><li>Plot, quiver, pcolor, many plot options </li></ul><ul><li>Many color schemes </li></ul>
8. 8. Importing Data <ul><li>Matlab can import data from a variety of sources </li></ul><ul><li>Can import using the Import Data tool or programmatically </li></ul><ul><li>XLSRead is good for importing .xls files </li></ul><ul><ul><li>[Numeric, txt, raw]=xlsread(File, Sheet, Range) </li></ul></ul>
9. 9. Basic Programming <ul><li>M-files store Matlab command lines </li></ul><ul><ul><li>Can be run from the command line </li></ul></ul><ul><ul><li>When run, they execute all of the commands contained in it as if you had typed these into a command window (like a keyboard macro) </li></ul></ul><ul><li>M-files can contain scripts or functions (or both or multiple functions) </li></ul><ul><ul><li>Function variables are local to that function </li></ul></ul><ul><ul><li>Scripts only operate on variables that are hard coded into their m-file </li></ul></ul>
10. 10. Some simple commands <ul><li>Some basic loops </li></ul><ul><ul><li>for i=1:10 … end </li></ul></ul><ul><ul><li>while(i<10) … end </li></ul></ul><ul><ul><li>if (a>10) … elseif (a<5) … else … end </li></ul></ul><ul><ul><li>switch a case 1 … case 2 … case 3 … … otherwise … end </li></ul></ul><ul><li>Formatting </li></ul><ul><ul><li>% comments out a line </li></ul></ul><ul><ul><li>%% can help divide a section </li></ul></ul>
11. 11. File directory structure <ul><li>Recommend that user m-files go in a MATLAB directory within “My Documents” </li></ul><ul><ul><li>Use subdirectories for various projects </li></ul></ul><ul><li>Put directories into matlab “path” allows calling functions from any directory </li></ul>
12. 12. Working “live” on command line <ul><li>From program, go “live” with keyboard command </li></ul><ul><li>“ who” command lists currently defined variables </li></ul><ul><li>Commands work – same as in program </li></ul><ul><li>Live graphs, or modifications to existing graphs </li></ul><ul><li>History of command input, accessed by arrow keys </li></ul>
13. 13. Fitting data <ul><li>Data displayed in a plot can be fit to polynomials </li></ul><ul><ul><li>Built in to plot window - tools/basic fitting </li></ul></ul><ul><li>Also can use matrix ‘backslash’ operator </li></ul>
14. 14. Basic Programming <ul><li>M-files </li></ul>
15. 15. Additional resources <ul><li>Matlab tutorial (pdf file) </li></ul><ul><li>Matlab built-in demos (in help) </li></ul><ul><li>Demos available on-line </li></ul><ul><ul><li>http://www.mathworks.com/academia/student_center/tutorials/launchpad.html </li></ul></ul><ul><li>User contribution repositories </li></ul><ul><ul><li>On mathworks web site </li></ul></ul>