Guest User

Untitled

a guest
Jul 16th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. In the SMDm-file, insert a figure command before the second plot command:
  2. 45 end
  3. 46 figure
  4. 47 plot(t,y2,’LineWidth’,3,’LineStyle’,...
  5. 48 ’—’,’Color’,’Blue’);
  6. Save and run the m-file.
  7. There will be two graphs created in windows labeled Figure 1 and Figure 2.
  8. While this example showed how to create multiple graphs from an m-file, we
  9. want to show both sets of data on a single graph. For this, we will need to use the
  10. hold command. The hold oncommand keeps the current graph open so that sub-sequent plotting commands will add to the current graph. There is also a hold off
  11. command that closes the graph from further additions. The use of the hold com-mand alone (without the value in parentheses) toggles the command between
  12. hold onand hold off. To prevent ambiguity, it is recommended that onor offbe
  13. specified.
  14. Since we will have more than one curve on the graph, we will need a legend to
  15. distinguish them.
  16. In the SMDfile, replace the figure command with a hold oncommand. Also,
  17. add thelegend command as shown:
  18. 45 end
  19. 46 hold on
  20. 47 plot(t,y2,’LineWidth’,3,’LineStyle’,...
  21. 48 ’—’,’Color’,’Blue’);
  22. 49 legend(‘Damping Coefficient = 0.1’,...
  23. 50 ‘Damping Coefficient = 0.2’);
  24. Note that in the legend command, the two curves are identified in the order in
  25. which they are created.
  26. Save and run the file. Make any desired edits (such as the font sizes of the leg-end and numbers on the axes) to the graph with the Property Editor. Click and
  27. drag the legend to the desired location.
  28. 166 CHAPTER 5 Plotting Data
  29. The finished graph is shown in Figure 5.60.
  30. Another useful MATLAB plotting command is fplot. To use fplot, the function to
  31. be plotted must be written as a MATLAB function m-file. The general form of
  32. the fplot command is as follows:
  33. fplot(‘functionname’,[x
  34. lower
  35. x
  36. upper
  37. ])
  38. where x
  39. lower
  40. and x
  41. upper
  42. are the lower and upper limits of the function arguments.
  43. That is, x
  44. lower
  45. and x
  46. upper
  47. define the domain of the independent variable. The fplot
  48. command can be used to plot built-in MATLAB functions in addition to function
  49. files that you generate. For example, we can plot the sin function for values of
  50. zero to 2 π radians by entering this command:
  51. >> fplot(‘sin’,[0 2*pi])
  52. To plot the displacement of our spring-mass-damper system, we must first create
  53. a function file.
Add Comment
Please, Sign In to add comment