Mike on the MATLAB Desktop
January 28th, 2008
Exploring your data with datatips
In the spirit of encouraging you to try out cell mode, lets look at a feature that will help you keep your focus in the editor while crafting your cells.
As I mentioned in an a previous blog entry (Running functions with input from the Editor in R2007b) I find it extremely useful to access all the information I need for a particular task from one location. This is less disruptive to my workflow, which means less context switching – and that means I get more work done!
We’ve already seen how MATLAB’s cell mode lets you group sections of code and then interactively run them each in any sequence you choose. (I’ve got something to cell you). This is really helpful when experimenting with your code – but there’s still an unnecessary step in your workflow. After each run of the cell, you have to switch focus over to the Workspace Browser and inspect your variables to ensure everything is in good order. You can eliminate that context switch by turning on datatips.
Datatips allow you to mouse over any variable defined in the base workspace and view its contents. In fact, if you do much debugging, you may have already noticed this feature as it gets turned on during debug sessions.
To turn on datatips in edit mode, goto Preferences -> Editor/Debugger -> Display and select Enable datatips in edit mode.
Now when a variable is defined in your workspace, you can mouse over it in the editor and view its contents like this:
Note also that with datatips-in-edit-mode turned on, datatips will popup in any M-file your editing (not just those using cells).
Explore your data!
07:02 UTC |
Posted in Editor, Preferences |
Permalink |
14 Comments »
You can follow any responses to this entry through the RSS 2.0 feed.
You can skip to the end and leave a response. Pinging is currently not allowed.
Leave a Reply
|
Very useful tip. I’m always typing “whos” into the command prompt to view the variables, but this way is much more efficient.
Thanks Quan. In addition to providing all the information whos supplies, datatips offers up the value of the variable as well…even if its an array.
-Ken
I like this feature in the debug mode, but I had to turn it off in the editor because it can be very distracting. There are times, however, when it would be handy, like the example you give with evaluating cells. It would be nice if there were (or maybe there is) a shortcut key combination to toggle this feature. What I currently do is highlight the variable in question and hit F9 to evaluate in the workspace.
Thanks for the feedback Eric. I agree that it could potentially be disrupting to have datatips on all the time. There is currently an open feature request to add quite a bit more customizability to datatips, and I’ve added your request for a toolbar button and/or shortcut key to toggle this feature to that request.
Note also that there is a MATLAB function that displays similar information to the datatips feature, aptly named datatipinfo. Maybe someone can come up with a creative solution using this function?
-Ken
Hi Ken – I know this thread is long dead, but I have a datatips question for you. I just started using Matlab 7.8.0 (2009a), and noticed that when I am at the bottom of my screen (and editor window), the datatips in the editor are shown below the variable I am looking at, which in this case is off the screen (I am on windows xp, on a dual-monitor situation). My memory of previous versions was that if there wasn’t room to display the datatip underneath the variable it would display it above the variable. In this case, I cannot read the values (since they are below my screen), and often work at the bottom of the editor or screen, since that’s where the empty space on the editor is. Is this a bug? Is there a fix? I’m sorry if this has been discussed before; I couldn’t find it in the discussion forum.
Thanks!
~Ben
Ben,
It is a bug, and it’s something we fixed in MATLAB R2009b.
Thanks Mike! I wonder if i can get my institute to upgrade…
Cheers
Hi Mike,
I am also using Matlab R2009a on Windows XP with dual monitors and somehow I don’t have the same bug as the one Ben has written about. However, I have the following observation(bug?): In debug mode or cell mode, information about some of my structure array variables are not shown completely in the in-editor-datatip (or as output of the datatipinfo fuction call) compared to the command window when typing the variable name as shown below (it shows the structure array having 8 elements where in fact it has 188). Is this also a bug that was fixed in 2009b? Thanks!
>> output
output =
188×1 struct array with fields:
info
results
>> datatipinfo(output)
output:
8×1 struct array with fields:
info
results
@Sam,
I am not sure about your particular piece of data, but we’ve made improvements to the datatip code in R2009b and R2010a.
Mike,
I had to do some additional digging and it turns out that this is a bug in the datatipinfo function as it explicitly skips the first 9 characters for sturctures and thus removes the first 2 characters of the information. This is easily fixed on my local copy and I hope this was fixed for R2009b and R2010a.
I like this feature in the debug mode. However, for some reason the datatip dose not appear anymore. Is there anybody who knows more about this…
I use Matlab 7.5.0 (R2007b). The ‘Enable datatips in edit mode’ in the ‘Preferences’ is turned on.
Thanks,
Peter
@Peter,
Can you explain about what you mean with “datatip does not appear anymore”? In order to show a tip there has to be a variable with the same name in the workspace. You’ll only see tips for variables in the current context.
I know the thread is old but in case you read this – why not make datatips configurable? For a lot of people in medical image processing where >3D matrices is the norm, it would be great to be able to see the dimension sizes rather than just the [4D] label that is assigned to such a variable. just looking for same behaviour as for dimensionality <=3.
I spend a lot of time doing size(myvariable) on 4Ds and it gets a little annoying and disturbs the work flow.
Soren
@Soren,
I will pass that suggestion on to the editor team. If you want to hack your install, you can do it by
then in the nested function sizetype add the following elseif to the big if block on the variable “D”
elseif D == 4 theSize = [num2str(s(1)), 'x', num2str(s(2)), 'x', ... num2str(s(3)), 'x', num2str(s(4))]; else theSize = [num2str(D) '-D'];I would not recommend hacking this to actually display the value of a 4-dimension variable, it would be too large to fit in the tooltip and needlessly waste memory.