MATLAB Community

MATLAB, community & more

Variable Editor 17

Posted by admin,

When the Array Editor was introduced back in MATLAB 5.0, it provided static snapshots of MATLAB double arrays.  It has evolved a lot since then, to provide dynamic editors for…


A lot of new functionality was added in R2008a, including


  • Editors for objects created in the new MATLAB class system
  • Improved Structure support
  • Support for Data Brushing
  • Other interface enhancements.

Because of all of these changes since Version 5, we felt that it was time to rename the Array Editor.  It’s now called the “Variable Editor” to reflect its enhanced capabilities.


Let’s take a look at some of the changes.  Create a variable and open it in the Variable Editor:


>> x = magic(10);

>> openvar x % Or go to the Workspace and double-click on x.



Here we see the Variable Editor with a new information bar bar located just below the toolbar.  It shows the name, size, and class of the current variable, as well as the same icon (based on data type) that’s shown in the Workspace.


We also see the new data brushing toolbar button.  Data brushing is a topic unto itself, worthy of a future posting (stay tuned – if you can’t wait to try it, checkout the documentation).


Structure Editing

We’ve enhanced structure editing to leverage a lot of the features that have been added to the Workspace in recent years.  To see this, let’s create a structure with some interesting data.


>> = magic(10);

>> = ‘Natick’;

>> s.temp = 70.2;

>> openvar s



As you can see, the Variable Editor shows the fields of the structure in the same way that the Workspace shows the variables in the Workspace.  Field (instead of Name), Value, Min, Max, and all of the other columns accessible in the Workspace are also shown here.  Further, all of the gestures for editing (clicks, context menus, and so on) are identical to those used in the Workspace. 


Object Editing

We’ve also added support for MATLAB class system objects.  Now, the public properties of objects are shown in the same way as the fields of structures.


Let’s examine an instance of the memmapfile object:

>> m = memmapfile(which(‘clown.mat’));

>> openvar m




Notice that the public properties of the object appear in the Variable Editor.


Normally, only the public properties of an object are visible.  But if you’re debugging an object, you’ll need to be able to get to the protected or private properties, too.  The Variable Editor supports that.  Let’s set a breakpoint in one of the methods of memmapfile, and watch what happens.


>> edit memmapfile

Set a breakpoint on the set.writable method (in R2008a, that’s line 132) by right-clicking on that line and selecting “Set/Clear Breakpoint.”


Now, do something to hit that breakpoint:

>> m.writable = false;


The debugger stops on that line of code.  In the Editor, you can see that the object being debugged is called “obj”.  To see the contents,

>> openvar obj



The Variable Editor opens, showing all of the properties, both public and private.  The ones that end users normally have access to are shown without any lock icons next to them.  In contrast, the private properties have little red locks next to them, to show you that they’re normally inaccessible.  You can only see them because you’re debugging one of the object’s methods.


These enhancements to Variable Editor should help to make interactions with your data more seamless. Let us know which Variable Editor enhancement you use most!


Comments are closed.

17 CommentsOldest to Newest

chee replied on : 1 of 17
Hi Bob, I have a question for using memmapfile. We can create an memmapfile object using m = memmapfile(which(’clown.mat’)); Can we just load a subset (say the first 100 row and cols) of the matrix simply using; subset =,1:100);? I tried that but it doesn't work. Can you suggest how to access the memory mapped matlab file? Thanks. Chee Can you
chee replied on : 2 of 17
Hi Bob, The question is still about memmapfile for matlab file: The code is as follows: mydata = [(1:100)' (1:100)']; save test.mat mydata -v6 m = memmapfile('test.mat','format',{'double',[100 2],'mydata'}); m.Data ??? Error using ==> memmapfile.memmapfile>memmapfile.hCreateMap at 257 I am wondering how to memory-map a .mat file. I guess there is some header information in the .mat file so that the data cannot be properly accessed.
Marcelino Martinez replied on : 4 of 17
Hi, I am using varible editor in order to check the values in a big array (more than 280000 rows) Is it possible to jump to a specific row or colum in variable editor ? Thank you very much
Bob Gilmore replied on : 5 of 17
Marcelino, Sorry, but that capability isn't available yet. We have it entered in our enhancement tracking system. Thanks for asking, --- Bob Gilmore
Daniel replied on : 6 of 17
Hi, I use Matlab R2008b, but I cannot see the private members of the obj I'm debugging. Are there any additional settings to be made in order to make them visible in the variable editor? Daniel
Ryan replied on : 7 of 17
Hi, I find the variable editor very useful now that it is possible to view my own objects. There seems to be a problem using dependent properties however. It seems that if I have more than a couple of them, none of my objects properties show in the Variable Editor anymore. Is there a way around this? I cannot find any documentation to suggest what I am doing wrong.
Thomas replied on : 9 of 17
Hi, The variable editor is very usefull to edit any kind of variable but i'd would like to know if there is a way to do something like :
modified_var = openvar('initial_var')
That is, edit a variable with the variable editor, modify it and then get the modified variable as output. Of course, i'd like to do this from inside a function. Thanks for any help
Mike replied on : 10 of 17
There's a few problems with this. The Variable Editor works on a different thread, so MATLAB imemdiately returns from the openvar command, before the user'd get a chance to update it. Second, openvar evaluates the variable name in the base workspace and not a function's workspace. Your best bet would be a custom GUI or one of the input dialogs. Try searching the file exchange for submissions like this one.
Yair Altman replied on : 11 of 17
Thomas - unfortunately, the Variable Editor is tightly-coupled to Workspace variables. One would perhaps expect it to be a generic data editor that merely accepts the data when opened, but in fact it continues to be coupled even later. You can see this by modifying the variable in the Workspace and seeing the change automatically reflected in the Variable Editor. An unfortunate side-effect of this design is that the Variable Editor needs to interact with the workspace (probably via JMI). Since there is only one Matlab computational thread, this interaction needs to wait for the user's function to exit (the '>>' prompt returning) before being able to query the variable data for display in the Editor. Bottom Line: you can't wait (synchronously) on the Variable Editor within your code. But, you CAN make this work if you modify your request such that a callback function is called when the Variable Editor editing has ended (the window is closed) - this makes the design asynchronous, which enables the JMI interaction. Note: The following uses some undocumented/unsupported features that may break in future Matlab releases or might cause your screen to go blind:
% Open the variable in the Variable Editor
drawnow; pause(0.5); % wait for client to become visible

% Get handle of variable's client in the Variable Editor
jDesktop = com.mathworks.mde.desk.MLDesktop.getInstance;
jClient = jDesktop.getClient(varname);
hjClient = handle(jClient,'CallbackProperties');

% Instrument the client to fire callback when it's closed

function my_callback(varEditorObj,eventData,varname)
   data = evalin('caller',varname);
   % do something with this modified data
Mike replied on : 13 of 17
For a MATLAB class object, there is not in the Variable Editor, but you can display the names of all the properties using the metaclass object:
metainfo = metaclass(x)
propList = metainfo.PropertyList
propertyNames = {propList.Name}
Yuri replied on : 14 of 17
Mike, I'm curious what is the purpose of the second argument of openvar function? The function definition is function openvar(name,array)" Any example of how it can be used? Thanks
Michael Katz replied on : 15 of 17
@Yuri, It's an undocumented, deprecated feature that is used by some of the toolboxes for customizing what gets displayed, when the function is used as a callback. It's not meant to be used from user functions or the command line.
Jim replied on : 16 of 17
Mike, I'd like to be able to seamlessly save the state of the VE whenever I end a session & restore it upon startup of the next. If I've got the list of variables open at session close (presumably through some code in finish.m), then I should be able to loop over that list in start.m and call openvar on each, right? It would be even nicer if the saved state could include assignments of variables to panes and pane sizes. Is there any way to do this? Thanks.
Chris Dewires replied on : 17 of 17
I have an xls document which I have uploaded onto the variable editor. Is there any coding I could use which converts each coloumn into a variabe and give them an individual name? ie. Mi,Ni and i?