Download presentation
Presentation is loading. Please wait.
1
Introduction to MATLAB Plotting LAB 3
2
Basic Task: Plot the function sin(x) between 0≤x≤4π
Create an x-array of 100 samples between 0 and 4π. Calculate sin(.) of the x-array Plot the y-array >>x=linspace(0,4*pi,100); >>y=sin(x); >>plot(y)
3
Plot the function e-x/3sin(x) between 0≤x≤4π
Create an x-array of 100 samples between 0 and 4π. Calculate sin(.) of the x-array Calculate e-x/3 of the x-array Multiply the arrays y and y1 >>x=linspace(0,4*pi,100); >>y=sin(x); >>y1=exp(-x/3); >>y2=y*y1;
4
Plot the function e-x/3sin(x) between 0≤x≤4π
Multiply the arrays y and y1 correctly Plot the y2-array >>y2=y.*y1; >>plot(y2)
5
Display Facilities plot(.) stem(.) Example:
>>x=linspace(0,4*pi,100); >>y=sin(x); >>plot(y) >>plot(x,y) Example: >>stem(y) >>stem(x,y)
6
Display Facilities title(.) xlabel(.) ylabel(.)
>>title(‘This is the sinus function’) >>xlabel(‘x (secs)’) >>ylabel(‘sin(x)’)
7
Plot Properties title legend ylabel xlabel
8
plot(x,y) x=[1 2 3 5 7 7.5 8 10]; y=[2 6.5 7 7 5.5 4 6 8]; plot(x,y)
Plot function plot(x,y) where the variables x and y are vector and must be of same size i.e the number of elements should be equal. x=[ ]; y=[ ]; plot(x,y)
9
plot(x,y,‘line specifiers’,‘PropertyName’,PropertyValue)
Plot function plot(x,y,‘line specifiers’,‘PropertyName’,PropertyValue) Line specifiers Line specifiers are optional and can be used to define the style and color of the line and the type of markers (if markers are desired). solid (default) dashed dotted dash-dot Line Style Specifier - -- : -. red green blue cyan Line color Specifier r g b c magenta yellow black white Line color Specifier m y k w
10
plot(x,y,‘line specifiers’,‘PropertyName’,PropertyValue)
Plot function plot(x,y,‘line specifiers’,‘PropertyName’,PropertyValue) Line specifiers Line specifiers are optional and can be used to define the style and color of the line and the type of markers (if markers are desired). plus sign circle asterisk point cross triangle (pointed up) triangle (pointed down) Marker type Specifier + o * . × ^ v square diamond five pointed star six pointed star triangle (pointed left) triangle (pointed right) Marker type Specifier s d p h < >
11
Stem plot figure X = linspace(0,2*pi,50)'; Y = [cos(X), 0.5*sin(X)];
stem(Y)
12
Subplots x = linspace(0,10); y1 = sin(x); y2 = sin(2*x);
figure subplot(2,2,1) plot(x,y1) title('Subplot 1: sin(x)') subplot(2,2,2) plot(x,y2) title('Subplot 2: sin(2x)') subplot(2,2,3) plot(x,y3) title('Subplot 3: sin(4x)') subplot(2,2,4) plot(x,y4) title('Subplot 4: sin(8x)')
13
Example: dual y-axis
14
Polar Plot theta = 0:0.01:2*pi; rho = sin(2*theta).*cos(2*theta);
figure polar(theta,rho,'--r')
15
Plot Matrix: comparison b/w datasets
X = randn(50,3); plotmatrix(X,'*r')
16
3D Shaded surface plot: SURF
[X,Y,Z] = peaks(25); figure surf(X,Y,Z); Sphere with two colors
17
MESH Plot [X,Y] = meshgrid(-8:.5:8); R = sqrt(X.^2 + Y.^2) + eps;
Z = sin(R)./R; figure mesh(Z)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.