graphs plotting in MATLAB
-
Upload
apurva-patil -
Category
Engineering
-
view
243 -
download
11
Transcript of graphs plotting in MATLAB
![Page 1: graphs plotting in MATLAB](https://reader031.fdocuments.us/reader031/viewer/2022021503/587a9ed31a28ab09758b6727/html5/thumbnails/1.jpg)
Miss. Patil Apurva PandurangM.Tech (Electronics)
1
![Page 2: graphs plotting in MATLAB](https://reader031.fdocuments.us/reader031/viewer/2022021503/587a9ed31a28ab09758b6727/html5/thumbnails/2.jpg)
x = 0:0.1:2*pi; % first value is 0, last is 2*pi & incrementad by 0.1
y = sin(x); % for sin wave
plot(x,y)
OR
x= linspace(0,2*pi,1000)
% taking 1000 samples between 0 to 2pi
y = sin(x); % for sin wave
plot(y)
0 1 2 3 4 5 6 7-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
2
![Page 3: graphs plotting in MATLAB](https://reader031.fdocuments.us/reader031/viewer/2022021503/587a9ed31a28ab09758b6727/html5/thumbnails/3.jpg)
plot(.)
>> x=linspace(0,2*pi,50);
>>y=sin(x);
>>plot(y)
stem(.)
>> x=linspace(0,2*pi,50);
>>y=sin(x);
>>stem(y)
0 5 10 15 20 25 30 35 40 45 50-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 5 10 15 20 25 30 35 40 45 50-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
3
![Page 4: graphs plotting in MATLAB](https://reader031.fdocuments.us/reader031/viewer/2022021503/587a9ed31a28ab09758b6727/html5/thumbnails/4.jpg)
title(.)
>>title(‘This is the sinus function’)
xlabel(.)
>>xlabel(‘time’) ylabel(.)
>>ylabel(‘sin(x)’)
legend(.)
>>legend ('sin_x')
grid
>> grid on
>> grid off
axis([xmin xmax ymin ymax])
Sets the minimum and maximum limits of the x- and y-axes
0 1 2 3 4 5 6 7-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
time
sin
(x)
This is the sinus function
sin(x)
4
![Page 5: graphs plotting in MATLAB](https://reader031.fdocuments.us/reader031/viewer/2022021503/587a9ed31a28ab09758b6727/html5/thumbnails/5.jpg)
0 1 2 3 4 5 6 7-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
time
sin
(x)
This is the sinus function
sin(x)
Data signal
X axis label
grids
Tick mark
legend
Graph title
Y axislabel
5
![Page 6: graphs plotting in MATLAB](https://reader031.fdocuments.us/reader031/viewer/2022021503/587a9ed31a28ab09758b6727/html5/thumbnails/6.jpg)
Multiple x-y pair arguments create multiple graph
x = 0:pi/100:2*pi;
y = sin(x);
y2 = sin(x-0.25);
y3 = sin(x-0.5);
plot(x,y,x,y2,x,y3)
0 1 2 3 4 5 6 7-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
6
![Page 7: graphs plotting in MATLAB](https://reader031.fdocuments.us/reader031/viewer/2022021503/587a9ed31a28ab09758b6727/html5/thumbnails/7.jpg)
plot(x,y,’line specifiers’)
Define style, color of line & type of marker
7
![Page 8: graphs plotting in MATLAB](https://reader031.fdocuments.us/reader031/viewer/2022021503/587a9ed31a28ab09758b6727/html5/thumbnails/8.jpg)
Line Specifies Line Specifies Marker SpecifiesStyle Color Type
Solid - red r plus sign +dotted : green g circle odashed -- blue b asterisk *dash-dot -. Cyan c point .
magenta m square syellow y diamond dblack k
0 1 2 3 4 5 6 7-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Example:
x=0:0.1:2*pi;y=sin(x);plot(x,y,'r-*')
8
![Page 9: graphs plotting in MATLAB](https://reader031.fdocuments.us/reader031/viewer/2022021503/587a9ed31a28ab09758b6727/html5/thumbnails/9.jpg)
fplot(‘function’,[limits])
E.g.
Plot the equation
x^3-2*cos(0.66*x)+4*sin(2*x)-1 in the limitbetween -3 & 3
>>fplot('x^3-2*cos(0.66*x)+4*sin(2*x)-1', [-3 3])
-3 -2 -1 0 1 2 3-30
-20
-10
0
10
20
30
9
![Page 10: graphs plotting in MATLAB](https://reader031.fdocuments.us/reader031/viewer/2022021503/587a9ed31a28ab09758b6727/html5/thumbnails/10.jpg)
Subplots subplot(m,n,P)
rowscolumns
position
x=0:0.1:2*pi;y=sin(x);subplot(2,1,1);plot(y)title('sin(x) wave')
y1=cos(x)subplot(2,1,2); plot(y1)title('cos(x) wave')
0 10 20 30 40 50 60 70-1
-0.5
0
0.5
1sin(x) wave
0 10 20 30 40 50 60 70-1
-0.5
0
0.5
1cos(x) wave
10
![Page 11: graphs plotting in MATLAB](https://reader031.fdocuments.us/reader031/viewer/2022021503/587a9ed31a28ab09758b6727/html5/thumbnails/11.jpg)
0 20 40 60 80-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1sin(x) wave
0 20 40 60 80-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1cos(x) wavex=0:0.1:2*pi;
y=sin(x);subplot(1,2,1);plot(y)title('sin(x) wave')
y1=cos(x)subplot(1,2,2); plot(y1)title('cos(x) wave')
Example
11
![Page 12: graphs plotting in MATLAB](https://reader031.fdocuments.us/reader031/viewer/2022021503/587a9ed31a28ab09758b6727/html5/thumbnails/12.jpg)
Example: x=0:0.1:4*pi;y=sin(x);subplot(2,2,1);plot(y)title('sin(x) wave')
y1=cos(x)subplot(2,2,2); plot(y1)title('cos(x) wave')
y2=sawtooth(x)subplot(2,2,3); plot(y2)title('sawtooth wave')
y3=rand(4)subplot(2,2,4); plot(y3)title('randam wave')
0 50 100 150-1
-0.5
0
0.5
1sin(x) wave
0 50 100 150-1
-0.5
0
0.5
1cos(x) wave
0 50 100 150-1
-0.5
0
0.5
1sawtooth wave
1 2 3 40
0.5
1randam wave
12
![Page 13: graphs plotting in MATLAB](https://reader031.fdocuments.us/reader031/viewer/2022021503/587a9ed31a28ab09758b6727/html5/thumbnails/13.jpg)
Example
clcclear allx=0:0.1:4*pi;y=sin(x);subplot(2,2,1:2);plot(y)title('sin(x) wave')
y2=sawtooth(x)subplot(2,2,3); plot(y2)title('sawtooth wave')
y3=rand(4)subplot(2,2,4); plot(y3)title('randam wave')
0 50 100 150-1
-0.5
0
0.5
1sawtooth wave
1 2 3 40
0.5
1randam wave
0 20 40 60 80 100 120 140-1
-0.5
0
0.5
1sin(x) wave
13
![Page 14: graphs plotting in MATLAB](https://reader031.fdocuments.us/reader031/viewer/2022021503/587a9ed31a28ab09758b6727/html5/thumbnails/14.jpg)
bar(x,y)
x=[1 2 3 4 5]
y=[1 2 3 4 5]
bar(x,y)
function creates
vertical Bar plot 1 2 3 4 5
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
14
![Page 15: graphs plotting in MATLAB](https://reader031.fdocuments.us/reader031/viewer/2022021503/587a9ed31a28ab09758b6727/html5/thumbnails/15.jpg)
barh(x,y)
x=[1 2 3 4 5]
y=[1 2 3 4 6]
barh(x,y)
function creates
horizontal Bar plot 0 1 2 3 4 5 6
1
2
3
4
5
15
![Page 16: graphs plotting in MATLAB](https://reader031.fdocuments.us/reader031/viewer/2022021503/587a9ed31a28ab09758b6727/html5/thumbnails/16.jpg)
stairs(x,y)
x=[0 1 2 3 4]
y=[1 2 3 4 6]
stairs(x,y)
function creates
stair plot
0 0.5 1 1.5 2 2.5 3 3.5 41
1.5
2
2.5
3
3.5
4
4.5
5
5.5
6
16
![Page 17: graphs plotting in MATLAB](https://reader031.fdocuments.us/reader031/viewer/2022021503/587a9ed31a28ab09758b6727/html5/thumbnails/17.jpg)
compass(x,y)
x=[1 2 3 4 5]
y=[1 2 3 4 6]
compass(x,y)
function creates polar plot
Location of points to plot in
“Cartesian coordinates”
2
4
6
8
30
210
60
240
90
270
120
300
150
330
180 0
17
![Page 18: graphs plotting in MATLAB](https://reader031.fdocuments.us/reader031/viewer/2022021503/587a9ed31a28ab09758b6727/html5/thumbnails/18.jpg)
pie(x)
x=[1 2 3 4 5]
pie(x)
function creates pie plot
Values are in terms of percentage
7%
13%
20%
27%
33%
18
![Page 19: graphs plotting in MATLAB](https://reader031.fdocuments.us/reader031/viewer/2022021503/587a9ed31a28ab09758b6727/html5/thumbnails/19.jpg)
Thank you…..
19