How to enable Editor data tips when editing functions (not scripts, not debugging)?
12 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Walter Roberson
2023-11-24
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 个评论
Walter Roberson
2023-11-25
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!