Matlab Tutorial Sessions
Matlab Tutorial Sessions
Learning Objectives:
1. Learn about the Matlab GUI and its components – Command prompt, workspace and
variable space
2. How numbers and strings are stored in Matlab memory
3. Entering vectors and matrices in Matlab
4. Loop and Conditional constructs
Variable space: A component of the workspace where values held by variables are displayed
when corresponding variables in the workspace are selected by double clicking
Set the current folder using the path toolbar beneath the toolstrip
1. Open editor by selecting New script, New or Open from the Home toolstrip (or)
2. Directly enter commands in the command prompt and press enter to execute
Numbers and strings are stored as 1-D vectors and/or multidimensional matrices called arrays
Note: Except inside matrices (i.e. square brackets), Matlab is insensitive to spaces i.e. Matlab
ignores spaces everywhere else
Note: Matlab distinguishes between upper and lower case variables i.e. A is different from a
Conditional Statements:
if condition 1
clause 1
else
clause 2
end
Note: All constructs end with an end keyword
Note: else clause may be omitted if not required
Note: All keywords begin with lower case alphabets and are followed by a space
Testing more than 1 condition:
if condition 1
clause 1;
elseif condition 2
clause 2;
else
clause 3;
end
Loop Constructs:
Loops are used to iterate over a list or an array: for and while
The for loop:
for iterator = start value : end value
body of for loop;
end
Note: iterator can be any variable name but a keyword
Important: All statements in the body or the clauses should end with a semicolon to suppress
output
References:
Matlab help documentation
Module 1, pages 539-557, Process control, modeling, design and simulation by Wayne Bequette
Matlab Tutorial Session 2, Date: January 7th and 8th 2015
Learning Objectives:
Functional programming:
Examples:
[row,columns] = size(A)
Note: A program in Matlab is a collection of statements which may or may not comprise
functions
Note: axis position is counted column wise in each row for subplot
Formatting options:
References:
Matlab help documentation
Module 1, pages 539-557, Process control, modeling, design and simulation by Wayne Bequette