MATLAB has many features to produce high quality plots. This section in no way explains all the plotting capabilities of MATLAB, or discusses all the ways in which things can be changed. Hopefully it will supply you with enough information to be able to create plots that are near enough to what you want.
The basic plotting command is plot. If you have defined two vectors (of the same length) named x and y, then plot(x,y) will generate a plot of y versus x. A word of warning: By default, MATLAB joins the points with straight lines in the order in which they are given. To plot the points in other ways, use the following commands:
For both lines and points, try these:
A full list of the available type of points and lines is available by typing help plot first at the MATLAB prompt. (You may need to type more on at the prompt to see all the information.)
The plots should be annotated with labels on the x-axis, the y-axis and with a title. To place a label on the x-axis, use xlabel; to place a label on the y-axis, use ylabel; and to place a title, use title.
Remember to always give pictures meaningful titles and axis labels.>> x=[1:10]'; %The numbers 1, 2, ... 10 >> y=randn(10,1); %10 by 1 vector of normally >> plot(x,y);This gives a plot joining the points with lines, but crosses would be better:
>> plot(x,y,'x');The plot and the axes should be labelled:
>> xlabel('x-values');
>> ylabel('y-values');
>> title('A plot of y versus x');
The following functions may be useful also:
To print the plots that are produced on the screen, the print command can be used, and usually the Print option from the File menu of the Figure works also. In some cases, it may be best to save the picture to a file, and then print the file. The print command in still used in this case, but in a different form. See the help for print for more information. (You may need to use more on.) According to the help for print, the command print -depson will print the current picture on an Epson or Epson compatible 9- or 24-pin printer. Also, print -depson lookatme.prt should produce a file called lookatme.prt that can be sent to an Epson printer. Type help print to see what other types of printers that MATLAB supports (like LaserJets, BubbleJets and colour printers).