Introduction to MATLAB Plotting LAB 3 Basic Task

Introduction to MATLAB Plotting LAB 3

Basic Task: Plot the function sin(x) between 0≤x≤ 4π n Create an x-array of 100 samples between 0 an 4π. >>x=linspace(0, 4*pi, 100); n Calculate sin(. ) of the x-array >>y=sin(x); n Plot the y-array >>plot(y)

Plot the function e-x/3 sin(x) between 0≤x≤ 4π n Create an x-array of 100 samples between 0 and 4π. >>x=linspace(0, 4*pi, 100); n Calculate sin(. ) of the x-array >>y=sin(x); n Calculate e-x/3 of the x-array >>y 1=exp(-x/3); n Multiply the arrays y and y 1 >>y 2=y*y 1;

Plot the function e-x/3 sin(x) between 0≤x≤ 4π n Multiply the arrays y and y 1 correctly >>y 2=y. *y 1; n Plot the y 2 -array >>plot(y 2)

Display Facilities n plot(. ) Example: >>x=linspace(0, 4*pi, 100); >>y=sin(x); >>plot(y) >>plot(x, y) n stem(. ) Example: >>stem(y) >>stem(x, y)

Display Facilities n title(. ) >>title(‘This is the sinus function’) n xlabel(. ) >>xlabel(‘x (secs)’) n ylabel(. ) >>ylabel(‘sin(x)’)

Plot Properties title legend ylabel xlabel

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=[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, ‘line specifiers’, ‘Property. Name’, Property. Value) 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). Line Style solid (default) dashed dotted dash-dot Line color red green blue cyan Specifier r g b c Specifier -: -. Line color magenta yellow black white Specifier m y k w

Plot function plot(x, y, ‘line specifiers’, ‘Property. Name’, Property. Value) 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). Marker type plus sign circle asterisk point cross triangle (pointed up) triangle (pointed down) Specifier Marker type square diamond five pointed star six pointed star triangle (pointed left) triangle (pointed right) Specifier s d p h < >

Stem plot n n figure X = linspace(0, 2*pi, 50)'; Y = [cos(X), 0. 5*sin(X)]; stem(Y)

Subplots n n n n x = linspace(0, 10); y 1 = sin(x); y 2 = sin(2*x); y 3 = sin(4*x); y 4 = sin(8*x); figure subplot(2, 2, 1) plot(x, y 1) title('Subplot 1: sin(x)') subplot(2, 2, 2) plot(x, y 2) title('Subplot 2: sin(2 x)') subplot(2, 2, 3) plot(x, y 3) title('Subplot 3: sin(4 x)') subplot(2, 2, 4) plot(x, y 4) title('Subplot 4: sin(8 x)')

Example: dual y-axis

Polar Plot n n theta = 0: 0. 01: 2*pi; rho = sin(2*theta). *cos(2*theta); figure polar(theta, rho, '--r')

Plot Matrix: comparison b/w datasets n n X = randn(50, 3); plotmatrix(X, '*r')
![3 D Shaded surface plot: SURF n n n [X, Y, Z] = peaks(25); 3 D Shaded surface plot: SURF n n n [X, Y, Z] = peaks(25);](http://slidetodoc.com/presentation_image_h2/81ea7f114bf3e6f2262ca413d1369d03/image-16.jpg)
3 D Shaded surface plot: SURF n n n [X, Y, Z] = peaks(25); figure surf(X, Y, Z); n Sphere with two colors
![MESH Plot n n n [X, Y] = meshgrid(-8: . 5: 8); R = MESH Plot n n n [X, Y] = meshgrid(-8: . 5: 8); R =](http://slidetodoc.com/presentation_image_h2/81ea7f114bf3e6f2262ca413d1369d03/image-17.jpg)
MESH Plot n n n [X, Y] = meshgrid(-8: . 5: 8); R = sqrt(X. ^2 + Y. ^2) + eps; Z = sin(R). /R; figure mesh(Z)
- Slides: 17