MATLAB Data Plotting Techniques for Multiple Functions

Slide Note
Embed
Share

Explore advanced MATLAB techniques for plotting multiple functions in a single plot and across multiple subplots. Learn how to create visually appealing plots using functions like plot, subplot, title, and legend. Enhance your data visualization skills through hands-on examples and practical applications of MATLAB's plotting capabilities.


Uploaded on Sep 28, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. AL-Mustaqbal University College COMPUTER APPLICATIONS: MATLAB Dr. Mayas Aljibawi 1

  2. Lecture Number 2 Lecture Number 2 Multi Data Plotting and Multi Data Plotting and 3D Plotting 3D Plotting 2

  3. Multiple Data Sets Plotting Ex/ Write a program to plot a three function of x (in one plot) , where y1= 2 cos(x) , y2 = cos(x) , and y3 = 0.5 cos(x) in the interval of 0 x 2 in step of / 100, then add labels and titles to the plot. x=0:pi/100:2*pi; y1=cos(2*x); y2=cos(x); y3=cos(0.5*x); plot(x,y1,'d',x,y2,'s',x,y3,'o') xlabel('x=0:2pi') ylabel('cos(2x),cos(x),cos(0.5x)') title('three function of cos(x)') legend({'cos(2x)','cos(x)','cos(0.5x)'},'fontsize',16) 3

  4. Multiple Data Sets in Multiple Plots It is also possible to produce a few subplots in on figure window. With the command subplot, the window can be horizontally and vertically divided into p r subfigures, which are counted from 1 to r, row-wise, starting from the top left. The commands: plot, title, grid etc. work only in the current subfigure. 4

  5. Example: Write a program to Plot a three function of x (in a separate plot) , where y1= sin(3x) , y2 = cos (5x ) ,y3 = sin (3x ) * cos (5x) in the interval of x from 1 to 4 in step of 0.1 then add titles to the plot. x = 1:0.1:4; y1= sin(3*x); y2= cos(5*x); y3= sin (3*x).*cos(5*x); subplot(1,3,1); plot(x,y1,'m-');title ('sin(3*x) ), subplot(1,3,2);plot(x,y2,'g');title('cos(5*x) ), subplot(1,3,3);plot(x,y3,'k-'); title('sin(3*x)*cos(5*x)') 5

  6. x = 1:.1:4; y1= sin(3*x); y2= cos(5*x); y3= sin (3*x).*cos(5*x); subplot(3,1,1) plot(x,y1,'m-'); title ('sin(3*x)') subplot(3,1,2) plot(x,y2,'g') title('cos(5*x)') hold subplot(3,1,3) plot(x,y3,'k-') title('sin(3*x)*cos(5*x)') 6

  7. subplot(2,2,1) x=0:0.101:10; y1 = sin(x); plot(x,y1) title('Subplot 1: sin(x)') subplot(2,2,2) y2 = sin(2*x); plot(x,y2) title('Subplot 2: sin(2x)') subplot(2,2,3) y3 = sin(4*x); plot(x,y3) title('Subplot 3: sin(4x)') subplot(2,2,4) y4 = sin(8*x); plot(x,y4) title('Subplot 4: sin(8x)') 7

  8. 3D Graphics Basic Plots A MATLAB surface is defined by the z coordinates associated with a set of (x,y) coordinates . for example , suppose we have the set of (x, y) coordinates: 8

  9. Z represent the distance of each (x,y) point from the origin (0,0) . to calculate z in MATLAB for the x and y matrices given above, we begin by using the mesh grid function, which generates the required , x and y matrices. [x,y] = meshgrid (1:4) // the Example Example Write a program to draw a 3-D plot of sine function for x,y in the interval from -8 to 8 in step of 0.5. the step step is is 1 1 by by default default [x,y] = meshgrid (-8:.5:8); R= sqrt (x.^2 + y.^2 ) ; z = sin (R); mesh (x , y , z ) 9

  10. Example Plot the function in the interval from -2 to 2 with step of 0.1. [x,y] = meshgrid( 2:0.1:2); z = y.*exp( x.^2 y.^2); mesh(x,y,z),xlabel('x'),ylabel('y'),zlabel('z ) 10

  11. End 11

More Related Content