How to enable Editor data tips when editing functions (not scripts, not debugging)?

2 visualizaciones (últimos 30 días)
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?

Respuestas (1)

Walter Roberson
Walter Roberson el 24 de Nov. de 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 comentarios
Walter Roberson
Walter Roberson el 25 de Nov. de 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.
Andres
Andres el 25 de Nov. de 2023
Yes, that's what I showed in the first two pictures. You could also copy the code in question to another Editor tab, then you would still be able to call the function, albeit not with your current code modifications.
All of this is just slightly less convenient (and not in line with what the Editor data tip preferences documentation says, see original post), imho.

Iniciar sesión para comentar.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by