Lecture 2 - Visualization and Programming in Matlab
Lecture 2 - Visualization and Programming in Matlab
EE 8207
LECTURE 2:
2022/2023
HOMEWORK 1 RECAP
Some things that came up:
Plotting a straight line
» x = 1:10
» plot (x, 0)
➢Not an error, but probably not what you meant
Use of semicolon – never required if one command per
line.
You can also put multiple commands on one line; in
this case, a semicolon is necessary to separate
commands:
» x = 1:10; y = (x-5).^2; z = x.*y;
» plot (y);
Usually we want to plot y versus x
(1) Functions
(6) Debugging
function keyword
help lines
for function Make sure you save changes to the
m-file before you call the function
for
statement
block Call the function iterate
in command window
if statement block
in variable nargin
Instructor: E.Tarimo Visualization and Programming 2022/2023
3. LINE PLOTS
PLOT OPTIONS
Can change the line color, marker style, and line style
by adding a string argument
Insert legend
For example:
color-map
Avoid loops!
Built-in functions will make it faster to write and
execute
Instructor: E.Tarimo Visualization and Programming 2022/2023
Vectorization
Avoid loops
➢This is referred to as vectorization
Vectorized code is more efficient for MATLAB
For example:
For example: