Introduction To MATLAB Programming: Fundamentals: Shan He
Introduction To MATLAB Programming: Fundamentals: Shan He
Shan He
Outline of Topics
Why MATLAB?
Programming in MATLAB
Plotting in MATLAB
Introduction to MATLAB programming
Why MATLAB?
What is it?
Key features
Why MATLAB?
A tour to MATLAB
Introduction to MATLAB programming
Matrix operations in MATLAB
>> help
Introduction to MATLAB programming
Matrix operations in MATLAB
Creating Matrices
Indexing
I To extract individual entries from a matrix, use indices inside
round brackets:
>> A(1,2)
I Use the ‘:’ operator to extract all entries along a certain
dimension:
>> A(1,:)
I Use ‘end’ statement to get the last index of a dimension:
>> A(end,1)
I Use logical indexing to find specific entries:
>> A(A>2)
I We can also use find() function to find specific entries:
>> A(find(A>2))
Introduction to MATLAB programming
Matrix operations in MATLAB
Matrix manipulations
Matrix manipulations
Sparse Matrices
Flow of Control
Creating functions
I Open a new file in MATLAB editor, or type: edit
filename.m at the command prompt.
I In you m file, begin by creating the function header:
function [output1 ,output2, output3...] =
myfunction(input1, input2...)
I We can use the inputs as local variables.
I All variables are local in a function.
I We must assign values to each of the outputs before the
function terminates.
I Although optional, it is better to end the function with the
“end” keyword
I Let’s see an example (download from here).
Introduction to MATLAB programming
Programming in MATLAB
1D/2D plots
3D plots
Customise plots