Skip to Main Content Skip to Search
Accelerating the pace of engineering and science

 

MATLAB Digest - July 2004

New Interactive Plot Creation Tools in MATLAB 7


by Stuart McGarrity

MATLAB 7 introduces a new set of tools to let you interactively create and edit plots without typing any MATLAB code. Now you can create plots from scratch and visualize your data much more quickly. You can also automatically generate the code to create the plot again with new data. This article describes the capabilities of these new tools and includes a video tutorial.

Interactive Plot Creation in MATLAB 7

Interactive plot creation and editing is performed in MATLAB 7 by using the plot tools that are launched from the figure window toolbar as shown in Figure 1.


Figure 1: Turn on the plot tools by clicking the button the figure toolbar. Click on image to see enlarged view.

You can launch the plot tools after opening a blank figure window. However, it is more likely that you will turn them on after creating an initial plot by selecting and plotting from the workspace browser or array editor, from a plotting function entered at the command window, or even from an existing .fig file.

These tools provide point-and-click functionality that enables you to:

  • Drag and drop new data sets onto the figure
  • Add new subplot axes
  • Change object properties
  • Add annotations and draw shapes

Figure 2 shows an example of the plot tools in use.


Figure 2: Plot tools being used to interactively create a plot of sensor data. Click on image to see enlarged view.

These new features can help you to create a quick plot from data in the workspace. They can also be used if you are unfamiliar with the calling syntax of the plotting functions or if you are generally inexperienced in MATLAB programming.

M-code Generation from Figures in MATLAB 7

In MATLAB 7, you can generate an M-code function, such as the one in Figure 3, from the graphic you created with plot tools (or with plotting functions entered at the command line). You do this by choosing Generate M-file... from the figure’s File menu.


Figure 3: Typical M-code function file generated from a figure. Once saved, this function can be called again with new data. Click on image to see enlarged view.

You can later call this function programmatically with new data, and therefore reuse your design work. This effectively lets you create your own custom plot routines. The code generated contains mainly user-level plotting commands such as plot, title, xlabel, ylabel, and so forth. If you are new to the MATLAB language, this feature can help you learn how to call the plotting functions.

In addition to generating code from the whole figure, you can generate M-code from an axes or an individual object. This is done by right-clicking on the object while the figure is in edit mode and choosing the Context menu option.

Video Tutorial of Plot Tools

This video tutorial demonstrates how to use the plot tools and M-code generation. It has an audio voice-over and plays automatically. You can control its playback with the controls at the bottom of the screen.

Video Tutorial (7min, 12 sec)

Contact sales
Subscribe to newsletters