How to enable Editor data tips when editing functions (not scripts, not debugging)?
11 views (last 30 days)
Show older comments
Once activated in Preferences/Editor/Display (in my R2023b Matlab installation), Editor data tips show up in scripts
and while debugging functions
as desired, but they do not show up when editing functions
According to https://www.mathworks.com/help/matlab/matlab_env/about-editor-debugger-preferences.html the data tips should appear "when you are editing a MATLAB code file".
I understand that in many cases data tips showing base workspace values might not be useful when editing functions, but sometimes it is convenient e.g. to quickly run code snippets from a function and monitor variables.
Is there an option to enable Editor data tips while editing functions? Has data tip behaviour changed in recent Matlab releases?
0 Comments
Answers (1)
Walter Roberson
on 24 Nov 2023
If you are not executing a function, then it has no workspace to hold values, so data tips inside the editted function would not make sense (except perhaps global variables or persistent variables.)
Likewise, after you have returned from a function, it's workspace has been destroyed and there is nothing to take the datatip of.
When you edit scripts, MATLAB assumes for datatip purposes that you will be evaluating the script in the base workspace, so it can reasonably datatip variables that are in the base workspace.
3 Comments
Walter Roberson
on 25 Nov 2023
Consider
function take5
%%
foo = 123;
%%
take6
function take6
disp(foo)
end
end
If you Run and Advance while pointing to the assignment to foo, then MATLAB runs the code and foo gets created in the base workspace.
If you then Run and Advance the next section, with the call to take6, then MATLAB complains inside take6 about foo not being defined.
When you extract that subset of the code into a script, then the foo inside take6 is no longer a reference to a nested variable. Inside scripts, functions do not search the base workspace looking for variables. Nested variables are only searched for when you have nested functions.
Now, if you have something like
function take7
%%
foo = 123;
%%
take6(foo)
function take6(foo)
disp(foo)
end
end
and you Run and Advance each part, then foo is first written into the base workspace, and then the second Run and Advance is running a script that can find foo in the base workspace to pass to the function, so a sensible result can be obtained (at the expense of clobbering whatever foo was in the base workspace.)
And it is true that if you go through that kind of work, that datatips are not available in the editor while you are executing by section.
I don't know... I think if I were in that kind of situation... well, I would probably be running under debugging instead. Or at worst I would comment out the function header so that it all became a script.
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!