Matlab: Graph Plots<br />
Tools for plotting<br />plot- plot(y) plots the values in vector y versus their index.  plot(x,y) plots the values in vect...
Tools for plotting<br />xlabel(&apos;string&apos;)  - 	Labels the x-axis with string.<br />ylabel(&apos;string&apos;)    -...
Tools for plotting<br />hold on / off - Normally hold is off. This means that the plot command replaces the current plot w...
Tools for plotting<br />subplot(m,n,p) -Divides the figure window into m rows, n columns and selects the pp&apos;th subplo...
Graph Components<br />The following picture shows the basic components of a typical graph.<br />
2-D plotting<br />To plot the function:<br />y = x2 for x 2 [-2; 2].<br /><ul><li>x = -2:0.2:2;
y = x.^2;
figure(1);
plot(x,y);
xlabel('x');
Upcoming SlideShare
Loading in...5
×

Matlab: Graph Plots

3,521

Published on

Plotting using Matlab

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,521
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Matlab: Graph Plots"

  1. 1. Matlab: Graph Plots<br />
  2. 2. Tools for plotting<br />plot- plot(y) plots the values in vector y versus their index.  plot(x,y) plots the values in vector y versus x. The plot function produces a piecewise linear graph between its data values. With enough data points it looks continuous.<br />stem- Using stem(y) the data sequence y is plotted as stems from the x-axis terminated with circles for the data values. stem(x,y) plots the data sequence y at the values specified in x.<br />
  3. 3. Tools for plotting<br />xlabel(&apos;string&apos;) - Labels the x-axis with string.<br />ylabel(&apos;string&apos;) - Labels the y-axis with string.<br />title(&apos;string&apos;) - Gives the plot the title string.<br />
  4. 4. Tools for plotting<br />hold on / off - Normally hold is off. This means that the plot command replaces the current plot with the new one. To add a new plot to an existing graph use hold on. If you want to overwrite the current plot again, use hold off.<br />legend(&apos;plot1&apos;,&apos;plot2&apos;,...,&apos;plot N&apos;) - The legend command provides an easy way to identify individual plots when there are more than one per figure.<br />axis([xminxmaxyminymax])- Use the axis command to set the axis as you wish.<br />
  5. 5. Tools for plotting<br />subplot(m,n,p) -Divides the figure window into m rows, n columns and selects the pp&apos;th subplot as the current plot, e.g subplot(2,1,1) divides the figure in two and selects the upper part. subplot(2,1,2) selects the lower part.<br />grid on/off - This command adds or removes a rectangular grid to your plot.<br />
  6. 6. Graph Components<br />The following picture shows the basic components of a typical graph.<br />
  7. 7. 2-D plotting<br />To plot the function:<br />y = x2 for x 2 [-2; 2].<br /><ul><li>x = -2:0.2:2;
  8. 8. y = x.^2;
  9. 9. figure(1);
  10. 10. plot(x,y);
  11. 11. xlabel('x');
  12. 12. ylabel('y=x^2');
  13. 13. title('Simple plot');
  14. 14. figure(2);
  15. 15. stem(x,y);
  16. 16. xlabel('x');
  17. 17. ylabel('y=x^2');
  18. 18. title('Simple stem plot');</li></li></ul><li>2-D plotting<br /><ul><li>x = -3:0.2:3; y1 = -x.^2; y2 = x.^2;
  19. 19. subplot(2,1,1);
  20. 20. plot(x,y1);
  21. 21. xlabel('x'); ylabel('y_1=-x^2');
  22. 22. gridon;
  23. 23. subplot(2,1,2);
  24. 24. plot(x,y2);
  25. 25. xlabel('x');
  26. 26. ylabel('y_2=x^2');</li></li></ul><li>2-D plotting<br /><ul><li>t = 0:pi/20:2*pi;
  27. 27. y = exp(sin(t));
  28. 28. plotyy(t,y,t,y,'plot','stem')
  29. 29. xlabel('X Axis')
  30. 30. ylabel('Plot Y Axis')
  31. 31. title('Two Y Axes')</li></li></ul><li>3-D Graphics<br /><ul><li>[x,y] = meshgrid(-3:.1:3);
  32. 32. z = x.^2+y.^2;
  33. 33. mesh(x,y,z);
  34. 34. xlabel('x');
  35. 35. ylabel('y');
  36. 36. zlabel('z=x^2+y^2');</li></li></ul><li>Visit more self help tutorials<br />Pick a tutorial of your choice and browse through it at your own pace.<br />The tutorials section is free, self-guiding and will not involve any additional support.<br />Visit us at www.dataminingtools.net<br />

×