Workspace plotting

 

 

Starting the workspace plotter

The workspace plotter is a fast way to plot the variables in your current workspace. There is no need for you to type in all those long variable names and incur the errors that result when you type them wrong. Just type plt (with no arguments) at the command prompt and a window will appear such as the one shown to the left. (This window was actually generated with the included pltvar.m script example which creates the variables listed and then calls plt with no arguments.) All the variables in your workspace (except for scalars and strings) will be listed in the workspace plotter figure. The size of the variable (row, column) appears right after the variable name. If your workspace contains many variables, the variable list may appear in several columns. If your workspace includes 1x1 structures which include vector fields, than these fields will also appear in the workspace plotter figure using the usual structure notation (struct.field)

Choosing a x-vector

The first thing you should do is select the x-vector that you want to plot along the x-axis. As you can see from the instructions (in blue) at the top of the figure, you should do this by clicking on the desired x-vector using the right* mouse button. You may click on any of the variables shown in white. Note that in this example, the variable called long_variable_name is grayed out. This is done because only a row or column vector is allowed. Since long_variable_name has three rows of 400 elements it can't be chosen as the x vector.

Suppose you choose to plot the 400 element row vector sec along the x axis. After you click on that vector, it turns red for identification and visibility and the tag ←x is placed after the variable name indicating this is the chosen x vector as shown to the left.

* Actually in this initial situation you can also select the x-vector with a left click. (Normally a left click is reserved for selecting y-vectors, but here you can't do that since a x-vector must be chosen first.)  So even though a left click is allowed here, you still might want to stick with the right click to develop a habit that will make things easier later on.

Choosing a y-vector

Next you must choose the array (or arrays) to plot along the y axis. The plot routine requires that one of the dimensions of the y array match the length of the x vector. So in this example, the y arrays must have either 400 rows or 400 columns. The first three and the last two variables in the list do not meet this condition, so they are grayed out and you will not be allowed to select them.

Suppose you then click on these 3 array names: long_variable_name, psvb3, and psvb4. As you click on them, the names will turn yellow and the tag ←y is placed after the variable names to indicate that these arrays are to be plotted along the y axis.

If you then click on the "Plot" button plt will create a plot containing five traces. The first 3 traces will be the 3 rows of the array long_variable_name. In the trace selection box, these traces will be identified as longv1, longv2, and longv3 respectively. (Underscores are not used when the six character trace identifiers are created). The fourth trace will contain the data from psvb3 and will be called psvb3 in the trace selection box. Similarly, the fifth trace will contain the data from psvb4 and will be called psvb4 in the trace selection box.

Since a single x vector is being used, the x vector name (sec) is used as the x-axis label. In this example, the y-axis is labeled with Y axis for lack of anything better. If you had selected just a single y-axis variable for plotting, that variable name would be used as the y-axis label.

Starting from the previous situation, suppose the numbers in psvb3 were far bigger than the other selected y variables. Thus the other traces are difficult to see when plotted on the same y-axis scale. One way to solve this problem is to plot psvb3 on the right hand axis and leave the other variables on the left side. To do this, double click on psvb3. Note that the color changes to orange and the ←y changes to ←yR to indicate that this variable will be plotted on the right hand axis. You may select as many traces as you want for either the left or right hand y axis. To change a ←yR (orange) to a ←y (yellow) single click a few times on the variable name. (The exact number of clicks depends somewhat on the situation.)
So far you have only selected a single x vector. Although this will be sufficient most of the time, the workspace plotter allows multiple x vectors to be selected. Suppose you now right click on seconds and vb2rep. (Since they are grayed out, they won't accept a left click, but in this situation they will accept a right click). These two variables will then turn red to indicate that they are to be used as x vectors. They will also be marked with ←x2 and ←x3 respectively and the ←x marking on sec will change to ←x1. The digits after the "x" make it easier to know which x vector you have selected for each y vector. Also the first two variables (b1catb3 and b2catb4), which were grayed out before, now turn white because these 800 element row vectors now can be plotted versus either x2 or x3.

Suppose you then click once on both b1catb3 and b2catb4. They will both turn yellow and be marked with ←y2 indicating that they should be plotted with respect to x2 (seconds). In this case there is more than one choice of x vectors, so if you click on b2catb4 again, its mark changes from ←y2 to ←y3 as shown in the figure to the left. Since there are no other possible x vectors to choose from, if you click on b2catb4 one more time the ←y3 mark will disappear and the variable name will change back to white, indicating that it is no longer selected.

Every time you click the "Plot" button, the workspace plotter will create a new figure window containing the plot you specified by the various ←x and ←y tags. When you have created many plots, pressing the "CloseAll" button is a convenient way to close all of these figure windows (although the workspace browser window itself remains open). If you have chosen to plot more than one y variable, the workspace plotter will attempt to identify the selected variables using the six character ID tags. For (1 x n) or (n x 1) vectors the first 5 characters and the last character of the variable name are used for the ID tag. For (n x m) arrays only the first 4 characters of the variable name are used since an extra character is needed to specify one of the rows or columns. If you have many long variable names, you may not be happy with the 6 character ID tags that are generated. In that case, you can specify longer ID tags by typing a command such as TraceIDlen=17 before calling the workspace plotter. (Try this before typing pltvar). However you will find that the 17 character ID tags run into the main plot axis. In this example using pltvar, and 17 character ID tags, you could fix that problem by typing pltopt = {'AxisPos',[1.8 1 .86 1 2.8]}; before starting pltvar. The "1.8" tells plt to make the blank space to the left of the axis 80% bigger (to make room for the bigger ID tags). The ".86" tells plt to make the plot width 86% of the former size so that the plot doesn't run off the right edge. The "2.8" tells plt to make the TraceID box 280% of its former size so that the large trace IDs fit inside. Unfortunately in the general case it may require a small bit of experimentation to determine the best choice for all these numbers. If you want to use more than 6 characters in the ID strings by default, put the TraceIDlen and pltopt assignments in the pltdef.m file (see below).
 

pltdef.m

If a file named pltdef.m exists on your Matlab path then that file will be run before the workspace plotter is opened. This file may contain any Matlab commands, however the usual use for this file is to allow defining workspace plotter defaults.

The workspace plotter looks for any variable that contains the characters pltopt anywhere in its name. If it finds any such variables it will use the parameters they contain as arguments to plt when you press the "Plot" button. For example suppose pltdef.m contains these two lines:

pltopt1 = {'Title','This is a plot title','ylim',[-2 7]};
pltopt2 = {'FigName','Workspace plotter'};


Then any plot created by the workspace plotter will have its y-axis lower and upper limits initialized to -2 and 7 and it will use the axis title specified in pltopt1 and the figure name specified in pltopt2. (See section three - "Command line arguments" - for a complete description of the arguments allowed). You can also specify default parameters in a similar manner from the command window. For instance, if before you press the workspace plotter's "Plot" button you type this into the Matlab command window:

another_pltoption = {'Xlim',[-10 10]};

then the workspace plotter will use those x limits as the default for subsequent plots. Note that it is picky about the variable name. For instance, it would not use any parameters that you defined in a variable called another_plt_option because of the underscore character after the "plt". The variable QuickpltOptions_A would also not be recognized by the workspace plotter because of the capital O, although that would work fine if you changed it to a lower case o.


pltdef.m may also define other variables unrelated to plotting options. For example you could include this in your pltdef.m:

UnitCirc = exp((0:.04:2)*pi*1j); % 50 point unit circle
circleX  = real(UnitCirc);
circleY  = imag(UnitCirc);


If you were often plotting poles and zeros in the z-plane, circleX and circleY would come in handy as a way to plot the unit circle - a much needed reference in z-plane plots.