Programming With Matlab
Programming With Matlab
30/08/2015
Objective
Introduce Matlab programming;
i) Understand script and M-files and their difference
ii) Learn how to incorporate help comments in a
function
iii) Learn how to create interactive M-files
iv) Learn the role of subfunctions and how they are
accessed
v) Learn how to create and retrieve data files
vi) Learn on vectorization and why it is beneficial
vii) Learn on anonymous function
Script file
Function files
Function files- start with the word function
function outvar=funcname(arglist)
% help comments
Statements
Outvar=value
On the
Command
window
5
LF_F15
MTH 510
30/08/2015
Subfunctions
Functions can call subfunctions
Command : fprintf
Examples
x == 0
Relationship
equal
x ~= 0
x<0
x>0
x <= 0
x >= 0
x > 0& y > 0
Not equal
x > 0| y > 0
Retrieving data
Less than
Greater than
Less or equal
Greater or equal
If x AND y are greater than zero
11
LF_F15
10
12
MTH 510
30/08/2015
13
Examples
x == 0
14
Example: Decisons
Relationship
equal
x ~= 0
x<0
x>0
x <= 0
x >= 0
x > 0& y > 0
Not equal
x > 0| y > 0
Less than
Greater than
Less or equal
Greater or equal
If x AND y are greater than zero
15
17
LF_F15
16
18
MTH 510
30/08/2015
Loop:for...end
19
Loop:while structure
20
Annonymous Functions
21
22
Function Functions
A function that operates on another function
2.5
1.5
0.5
0
0
0.2
0.4
0.6
0.8
1.2
1.4
1.6
1.8
23
LF_F15