Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
68 views

DSP Using Matlab® - 2

Uploaded by

api-3721164
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

DSP Using Matlab® - 2

Uploaded by

api-3721164
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 11

Lecture 2: Plotting

Prof. Dr. Salina A.


Samad
Mr. Iskandar Yahya
Basic Plotting
In the first lecture, we’ve seen a basic 2-D
plot.
E.g.
>> x=linspace(0,4*pi,200);
>> y=sin(x);
>> plot(x,y);
>> title('A simple plot using
MATLAB');
>> ylabel('SIN(x)');
>> xlabel('x (Radians)');
MATLAB
Environment
Plotting in MATLAB Intro:
We can also plot multiple traces on a single
plot:
>>
x=linspace(0,2*pi,100)
;
>> y1=sin(x);
>> y2=cos(x);
>> y3=sin(x).*sin(x);
>> plot(x,y1,x,y2,x,y3)
Basic Plotting
Use “hold” function to draw a new plot
without removing the old plot.
Type “Hold on” and then followed by the
usual plotting commands.
This function is latching. So you need to type
“hold off” to remove old plots when you want
to begin a new plot.
Let’s try:
>> hold on
>> plot(x,cos(x))
Basic Plotting
New plot:
Plotting Styles
Line stlyes, markers, and colors for plot
Colour Color Marker Marker Line Line
Code Code Style Stlye
Code
y Yellow . Point - Solid
m Magenta 0 Circle : Dotted
c cyan x X-mark -. Dashbdo
r Red * Plus -- tdashed

g Green S Star
b Blue d Square
w White v Diamond
k black ^ Triangle
< Triangle
> Triangle
p Pentagra
h m
hexagra
Plotting Styles
Example:

>> x1=linspace(0,2*pi,10);
>> x2=linspace(0,2*pi,50);
>> x3=linspace(pi,2*pi,100);
>> x4=linspace(pi/3,2*pi,150);
>> y1=sin(x1);
>> y2=cos(x2);
>> y3=abs(sin(x3));
>> y4=sin(x4).*sin(x4);
>> plot(x1,y1,'gs', x2,y2,'kp:', x3,y3, x4,y4,'r--');
>> legend('sin(x)', 'cos(x)', 'abs(sin(x))', '(sin(x)*sin(x))',3)
>> xlabel('x - Radians');
>> title('Various Trigonometric Functions');
Plotting Styles
Example:
Plotting Styles
Change
background
colour use
“whitebg”.
This toggles
between
white and
black
background
Change back
to white type
“whitebg(‘w’
)”.
Plotting Styles
Place grid on
the current
plot.
Add “grid
on” on the
end of the
last
example.
Type”grid
off” to
remove grid.
Plotting Styles
To set the axis, use “axis” command.
axis ([Xmin Xmax Ymin Ymax]) – this
form specifies min and max limits for the
x- and y-axes.
axis auto – This form returns the axis
control back to matlab and allows matlab
to choose the axes limits automatically
You can use the “axis” to zoom to a
specific portion of the plot. Try this.

Later, when we are doing our tutorial


example, we will see other plotting
functions.

You might also like