Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Matlab

Similar presentations


Presentation on theme: "Introduction to Matlab"— Presentation transcript:

1 Introduction to Matlab
Dr. Milica Markovic

2 Finding Matlab Find matlab by going to: Start All Programs Matlab

3 Command Window Don’t use command window to directly type-in Matlab commands, unless you want to use Matlab as a basic calculator.

4 Matlab as a calculator

5 To write Matlab program, open a new script (editor) file first by going to File, New, Script
This is a script (or editor) window! Type your Matlab code here! In Matlab you don’t have to declare variables first! I just wrote a=11 Use letters, numbers and _ (underscore) for variable names. Always start the variable name with a letter.

6 To run Matlab program, press F5 or the green triangle shown below.
Always start the name of your file with a letter, and you can also use numbers or underscore _

7 Clear all command clears all variables in memory
Clear all command clears all variables in memory. clc clears command window contents. Always start your code with the first two lines Clear all and clc.

8 More tips for naming Matlab files
To save the new file as yourname.m go to File, Save As. Type yourname.m Be careful when you name a matlab file: (a) Avoid all special characters. (b) Do not use space (c) Do not start the le name with a number. (d) When you start writing your code, do not name any variables the same as the name of your file. (e) Do not name it sin, cos, or any other function that is likely to already exist.

9 Good code-writing practice: comments!

10 After running code with lot’s of computations:

11 To suppress printing in command window
Put ; at the end of the line you want to suppress

12 Use Matlab to help you assemble the report
When you are done with one matlab code, save the matlab file, then “publish” it, by doing the following: (a) Open the File pulldown menu (b) Select Publish conguration for new_file.m (this is your matlab le name) (c) Select Edit Publish Congurations for XYZ.m (d) A new window opens whose title is “Edit Congurations"

13 Selecting the type of file for publising
Select doc (you should also see html, xml, latex, doc. ppt and pdf)

14 Now Publish the File (a) Go to File, Publish
(b) Be patient it takes about 20 seconds to make a published le (c) You can then edit this le, add comments and put all doc files together (d) Finally, make a pdf from your final .doc file

15 Basic computation

16 Creating Arrays Tip: To make a column vector, separate entries with a ; or use a transpose operation g=[1 2 3]’

17 Colon Operator start_value: step: stop_value For example: 1:0.1:2
>> clear all >> fall2012 ans = Columns 1 through 6 Columns 7 through 11 >>

18 Another way to make an array
Linspace(start, end, how_many_points) clear all clc linspace(1,100,10) ans = >>

19 Creating Matrices Tip: g(2)=4, g(4)=5, g(5)=3, g(10)->error

20 Ploting

21 Add features to graph

22 Sinusoidal Functions

23 Making Cool Graphics

24 This is called “Graphics Window”


Download ppt "Introduction to Matlab"

Similar presentations


Ads by Google