Auxiliary plt functions

 

 

These are functions provided by plt that are only peripherally related to its usual data plotting capability:

ftoa
(float to
ascii)  
s = plt('ftoa',fmtstr,x,delim) returns in string s an ascii representation of the number x according to the formatting string fmtstr. The  argument may also be a vector in which case the optional string argument delim is inserted between the vector elements. If delim is omitted, a single space is used as the delimiter. Row and column vectors are represented identically. If x is a matrix, then a representation of x(:) is returned.

If fmtstr is of the form '%nw' then s will be the string representation of x with the maximum resolution possible while using at most n characters - not counting the decimal point if one is needed. If the field width is too small to allow even one significant digit, then '0' is returned.

If fmtstr is of the form '%nv' then s will be the string representation of x with the maximum resolution possible while using exactly n characters - not counting the decimal point if one is needed. If the field width is too small to allow even one significant digit, then '0' is returned.

These formats are typically used to generate strings to fit into gui objects of a fixed width. The reason the decimal point is not counted is that with the proportional fonts generally used in these gui objects, the extra space taken up by the decimal point is insignificant.

fmtstr may also use any of the numeric formats allowed with sprintf. For example:

plt('ftoa','%7.2f',x) is equivalent to sprintf('%7.2f',x)

 

vtoa
(vector to
ascii)  

 

s = plt('vtoa',fmtstr,x) is identical to 'ftoa' above except that if x is a vector of length two or more the angle bracket characters ([ ]) are added surrounding the string. If x is a scalar, there is no difference between vtoa and ftoa . The optional argument delim is also allowed in this call.

 Examples:

disp(['numerator polynomial = ' plt('vtoa','%6.2f',bc)]);

fprintf(fID,'%6d: sloss=%6.1f, coef = %s\n',...
        ntry,sloss,plt('vtoa','%5w',coef));
 

 

datestr
(serial date number to
ascii)  
s = plt('datestr',datenum,fmt) is similar to s = datestr(datenum,fmt)

except that it displays the time with 1 millisecond resolution instead of 1 second resolution used by the Matlab datestr function. You should only use formats that include the number of seconds in the result. If fmt is not included in the argument list, format 0 is assumed. For example:

a = now; [plt('datestr',a) '   ' datestr(a)]

Will respond with something like:

21-Jan-2007 10:28:02.898   21-Jan-2007 10:28:03

Type help datestr for a description of the allowable formats. You will find format 13 useful when the date is not required, i.e. plt('datestr',now,13) which will return something like: 10:28:02.898

 

metricp  
(metric
prefixes)

[Ret1, Ret2] = plt('metricp',x);

Used to converts a number to a form using standard metric prefixes. Ret1 is the metric prefix (in Ascii) that is most appropriate for displaying the value x, and Ret2 is the number you should multiply x by. For example, if x is in volts, you can display it using a metric prefix as:

[pfix, mult] = plt('metricp',x);
disp([num2str(x*mult) ' ' pfix 'Volts']);

 

grid
(grid line
functions)
The trace color of the native Matlab axis grid lines can't be independently set leading to grid lines that over power the display. These grid line functions are designed to solve this problem by providing grid lines of whatever color you choose. The grid line functions are:
 

plt('grid',ax,'init',color,erMode,In6,In7,In8,In9)
     -
Initializes grid lines of color color with erase mode + on axis ax.
              color is optional with default [.3 .3 .3] and erMode is optional with default 'xor'.
          -  In6,In7 is an optional parameter/value pair to apply to the grid lines
          -  In8,In9 is an optional parameter/value pair to apply to the grid lines

plt('grid',ax,'toggle')      - toggle grids (on/off)

plt('grid',ax,'get')      - get current on/off state of grids

plt('grid',ax,'off')      - turn grids off

plt('grid',ax,'on')       - turn grids on

plt('grid',ax,'update')   - update grids

plt('grid',ax)            - update grids (same as above)


All the above calls return 1 if the grids are on and 0 otherwise.

To experiment with these functions, try typing this at the command prompt:

>> a = axes;             % create axis
>> plt('grid',a,'init'); % draw grid lines
>> set(a,'ylim',[0 6]);  % change axis limits
>> plt('grid',a);        % update grid lines

 

edit
(edit
text
object)  
Sometimes a GUI needs many numeric and character controls in a small space. Matlab's usual uicontrol('Style','Edit') controls may be used but they use up so many extra pixels that a complicated GUI will quickly become overly cluttered. The edit function of plt fills this need. With numeric controls, we often would like to change the value by small amounts quickly and repeatedly. Matlab's slider control (or plt's slider object described below) fills this need well, however both take up too much space to use many of them is a single GUI. For this reason, several features of the plt edit object are tailored specifically for incrementing and decrementing numeric controls. To create an edit text object use the command:

H = plt('edit','PropName1','PropVal1','PropName2','PropVal2',...);

where:
 
Property Name Property
Value
value The numerical value of the edit text object (zero if it is a string type).
callbk A callback to be executed when the edit text object is changed.
Occurrences of '@VAL' will be replaced with the current value.
Occurrences of '@OBJ' will be replaced with the 8192 times the edit text handle.
enable 0=disable, 1=enable (default=1). If disabled, the text will still be visible, but may not be modified.
min The minimum allowed value (default = -1e9)
max The maximum allowed value (default = 1e9)
incr The increment value for a numeric plt edit object. (default = 1) If the edit object's value is a multiple of "incr" then when you click on the right/left side of the center of the object, the value of the object is increased/decreased by "incr". It is quite common to set this parameter to 1, which allows easy incrementing and decrementing of integer controls.
length The length of the vector allowed as the edit value. Usually length=1 indicating the edit value must be a scalar. If length=4 (for example), an allowed edit value must be a row or column vector of length 4. Two special cases are length=-1 and length=0. length=-1 is used to indicate that a numeric array of any length is a legal value. length=0 is used for string edit objects i.e. the edit string is not interpreted as a number or vector. (default = 1)
format The format conversion string used to display numeric edit objects (default = '%7w'). See ftoa above for a description of the formatting codes.
***** If a property name is given which isn't in the list above then the property is applied to the text object itself. (It must be a valid text property.) The text color ('color') is usually set this way, however if that property is not specified, the default color is [1 1 .4].

The above calls create the edit text object and returns the handle of the text object created. This handle (H) is used as an argument in the calls below:

plt('edit',H,'PropName1','PropVal1','PropName2','PropVal2',...);
If H is a scalar, the specified property values (using items from the table above) are applied to the edit text object identified by handle H. If H is a vector then PropertyName1 of H(k) is set to the kth row of PropertyValue1. If PropertyValue1 doesn't have that many rows, the last row will be used. Only 1 property is allowed.

plt('edit',H,'get','value')
returns the numeric value of the specified edit text object

Keyboard and mouse behavior:
Right clicking on the edit text object always "opens" the object for editing. What this means is that the old edit string appears with the cursor (underscore) at the end of the string indicating that it is ready to accept keys typed at the keyboard. If you start typing right away, the new characters typed will be appended to the end of the old string. To insert the new characters at a point other than the end, simply move the cursor to the desired point using the left/right arrow keys. To remove characters, press <Backspace> or <Delete> to remove a character before or after the cursor. Pressing <Delete> when the cursor is at the end of the string deletes all the characters. This special case makes it easier to enter a new string that bears little resemblance to the previous entry. Note that while typing, the text object is shown in a different color to remind you that a new value is being entered. When you press <Enter>, the new string is accepted and the color returns to the original. If you type an invalid entry, the word "error" will appear. Click again on the "error" string to try the entry again or to recover the previous entry (via <Esc>). A summary of the special keys follow:
 
<Esc> The edit text object is closed for editing and the original text value is restored as if the edit object was never opened for editing.
<Backspace> Deletes the character on the left side of the cursor.
<Delete> Deletes the character on the right side of the cursor. If the cursor is at the end of the string, all the characters are deleted leaving only the underscore cursor.
<Right arrow> Moves the underscore cursor one position to the right.
<Left arrow> Moves the underscore cursor one position to the left.
<Enter> Closes the edit text object, accepting the current entry (without the underscore cursor) as the new value.
<Click> Clicking the mouse on the edit text object while it is open has the same effect as pressing <Esc> on the keyboard.
i When entering a scalar value, if lower case "i" (increment) is entered as the last character, this indicates that the entered value should be used as a new "incr" parameter for the object. In this case the text object value from before the object was opened is retained.

Left clicking on the edit text object also opens the object for editing except for one important exception. This exception happens when both of the following conditions are met:

  • The edit text object is a scalar (i.e. the length parameter is equal to one).
  • The current edit object value is an exact multiple of the "incr" parameter.

Under those conditions, when you left click on the edit text object, its value is incremented or decremented by the object's "incr" parameter. Weather the value is incremented or decremented depends on the position of the mouse click. If you click to the right of the edit object's center, the value will be incremented. Likewise, the value will be decremented for clicks to the left of center. As an example, suppose the current edit text object has a value of 259, and the increment parameter is 1. Left clicking on the 9 will change the edit object's value to 260 (because the 9 is right of the center of the text string). On the other hand, left clicking on the two will decrement the value by one. Now suppose you right click on the object and type "259.5<enter>". The new edit object value becomes 259.5, which you will note is not an even multiple of "incr". Because of this, additional left clicks will not increment/decrement the object's value as before. However left clicks will again increment/decrement the control value after either of the following actions:

  • Clicking on the object and entering an integer value into the control
  • Clicking on the object and entering ".5i" (or any other number than evenly divides 259.5).

Whenever a number is being typed in, you may also type an expression instead. For example, the following entries are all equivalent:

  • 5

  • abs(3+4i)

  • [2 1] * [2 1]'

  • sqrt(3*2^3-cos(pi))

Typing sum(get(gca,'xlim').*[0 1])' would be equivalent to typing in the current upper x axis limit. And to be really perverse, typing log(-1)/(2*pi) would be equivalent to the ".5i" entry mentioned above.

See the curves.m example program for an example of how to use edit text objects as well as the popup text objects described below.
 

pop
(popup
text
object)  
Occasionally in a complicated GUI, many popup menus are needed in a space too small to fit Matlab's normal uicontrol('Style','Popup') popups. The pop function of plt fills this need. To create a plt popup text menu object use the command:

H = plt('pop','PropName1','PropVal1','PropName2','PropVal2',...);

where:
 
Property Name Property
Value
choices A cell array of strings specifying the choices given when the popup is selected.
index An integer specifying the current choice (1 = the 1st choice)
callbk A callback to be executed when the popup value is changed.
Occurrences of '@IDX' will be replaced with the popup index
Occurrences of '@STR' will be replaced with the popup string
colorbk The background color used when the popup is open. (default = [0 .3 .4]);
colorfr The foreground color used when the popup is open. (default = [.1 1 .9])
location height or [x y width height] for the popup.
offset y or [x y] offset added to location when popup is open.
enable 0=disable, 1=enable (default=1)
hide A list of objects to hide before opening the popup. After the selection is made, these objects are shown again (unless they were hidden before the popup opened). This can be used it remove the distraction of objects overlapping the popup list.
interp 'none' or 'tex' (default='none')
***** If a property name is given which isn't in the list above then the property is applied to the popup text object itself. (It must be a valid text property.)  The text color ('color') is usually set this way, however if that property is not specified, the default color is [1 1 .4].

The above calls create the popup text object and returns the handle of the text object created. This handle (H) is used as an argument in the calls below:

plt('pop',H,'PropName1','PropVal1','PropName2','PropVal2',...);
If H is a scalar, the specified property values (using items from the table above) are applied to the popup text object identified by handle H. If H is a vector then PropertyName1 of H(k) is set to the kth row of PropertyValue1. If PropertyValue1 doesn't have that many rows, the last row will be used. Only 1 property is allowed.

plt('pop',H,'get','index')
returns the index of the currently selected choice (1 = 1st choice)

plt('pop',H,'get','string')
returns the string corresponding to the selected choice.

plt('pop',H,'get','choices')
returns the cell array of choices.

Mouse behavior:
Left clicking on the popup text object "opens" the popup. What this means is that the popup string is replaced by a list of the popup choices (rendered using colorfr/colorbk). The user then clicks on the desired choice which then becomes the new text string. Right clicking on the popup text object changes the text string to the next available choice. If the last choice is already selected, then right clicking will change the text string to the first available choice (in the "choices" array).

See the curves.m example program for an example of how to use popup text objects as well as the edit text objects described above.
 

slider
(pseudo
slider
object)           

To use a slider to enter a numeric value in a gui application, besides the slider object itself one generally also wants an edit box to show the current slider value as well as to allow data entry by typing the number. Usually a label is required to identify the data and two fields that indicate the minimum and maximum values allowed are also handy. The pseudo slider object combines these five objects into one and is included in plt since many gui applications designed around plt may require sliders. To create a slider, use the command:

H = plt('slider',In1,In2,In3,In4,In5,In6,In7)

  This creates a pseudo object that has the 5 following sub objects:

  ------------label----------
  min----value editbox----max
  -----------slider----------

plt returns the pseudo slider's handle (H). This handle is required in the get and set commands to read and modify the pseudo slider's properties.
The arguments of the slider 'init' command are:

   In1 [x,y,width] in pixels or normalized units. (Mixing units is ok - values less than one are assumed to be normalized). [x,y] are the coordinates of the upper left corner of the pseudo slider label. If width is missing 0.13 is assumed. In1 is the only required parameter for this function.
   In2 [value, smin, smax, emin, emax]
value is the initial value assigned to the slider.
smin/smax are the slider values at its leftmost/rightmost position.
emin/emax are the smallest/largest values allowed when entering numbers into the edit box. If emin and emax are missing, 1e-99 and 1e99 are assumed. If In2 is not supplied, [50 0 100] is assumed.
   In3 Slider label. If you don't want a label, don't supply this parameter, or set In3 to ''.
   In4 Slider callback. This expression will be evaluated whenever the user moves the slider control or enters a number in the edit box. Occurrences of '@VAL' will be replaced with the current value. If you don't need a callback don't supply this parameter or set In4 to ''.
   In5 This parameter controls how the slider moves when the slider left/right arrows are clicked or when clicking in the space to the left or right of the slider button.
  In5 Movement Quantization
   1 Linear none (default if In5 is missing)
   2 Linear rounded to nearest integer
   3 Linear rounded to nearest power of two
 [4 q] Linear rounded to nearest multiple of q
   5 Logarithmic none

 [6 q]

Linear always equal to 1 (slider arrows)
always equal to q (slider trough)
Note: q defaults to 10 if not specified (modes 4 and 6).
   In6 [fmin; fval; fmax]
fmin/fmax are formatting strings for the min/max labels and fval is the formatting string for the edit box. These strings may contain c style printf formatting codes or the w and v formats defined in the plt('ftoa') commands.
For example: In8 = ['%2.1f';'%5w  ';'%3d  ']
or the equivalent: In8 = {'%2.1f','%5w','%3d'}

If a single string is provided it is assumed to be the format string fval in which case '%2w' and '%3w' is assumed for fmin and fmax respectively. If In6 is not provided, then ['%2w';'%6w';'%3w'] is assumed.

   In7 [LableBG; EditBG; LabelFR; EditFR]
This is an array containing 3 columns and up to 4 rows. Columns 1/2/3 respectively represent the proportion (0 to 1.0) of red/green/blue used in the control. The first two rows are the background colors for the label and edit fields respectively. The last two rows are optional and contain the label and edit field foreground colors. If the foreground colors are not specified black is assumed (i.e. [0 0 0]). If In7 is not provided [.75,.75,.75; 0,1,1] is assumed.


For the commands below, H is the handle returned from the above slider initialization command.

The get commands:

plt('slider',H,'get') returns the pseudo slider's current value
plt('slider',H,'get','value') same as above
plt('slider',H,'get','vis') returns 1 if the slider is visible, 0 otherwise
plt('slider',H,'get','ena') returns 1 if the slider is enabled, 0 otherwise
plt('slider',H,'get','obj') returns the slider object handles:
[  Label
   Slider
   MinText
   MaxText
   EditBox ]

The set commands:

plt('slider',H,'set',a) Sets the slider to value a.
Returns a possibly limited value.
plt('slider',H,'set','value',a) Same as above
plt('slider',H,'set','val',a) Same as above except the slider callback is not executed
plt('slider',H,'position',a) Sets the slider position.
(See In1 in the initialization section).
plt('slider',H,'set',...
    'minmax',a,b)
  • a contains [smin,smax,emin,emax]
    (see In2 in the initialization section)
  • b is a new slider value (optional)

Returns a possibly limited value.

plt('slider',H,'set','visON') Makes slider visible.
plt('slider',H,'set','visOFF) Makes the slider invisible.
plt('slider',H,'set','enaON') Enables the slider.
plt('slider',H,'set','enaOFF') Disables the slider
plt('slider',H,'set',...
    'label',a)
Sets the label string to a. If a is empty, the label is made invisible.
plt('slider',H,'set','mode',a) Sets the slider movement mode.
(See In5 in the initialization section).
Returns a possibly limited value.