How to monitor a variables that is outside of a function
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
fa wu
le 28 Juil 2023
Commenté : Walter Roberson
le 29 Juil 2023
This code . I type "aValue =SimpleHandle(10);" and then type "aValue. assignVar(20) ; %"
The programe will run in classdef SimpleHandle's methods "function assignVar(obj,var)" ,there is a Breakpoints. So programe will stop in obj.var = var;
At the same time ,I want to observe "aValue.var" ,but it isn't in workspace! because programe in "function assignVar(obj,var)",that make sense. But I type "aValue.var" in command line. Matlab notice "The function or variable 'aValue.var' is not recognized"
So is there any way can observe a variables that is outside of a function when programe run in the function? I think it is very useful as debugging.
"classdef SimpleHandle < handle
properties
var
end
methods
function obj = SimpleHandle(var)
obj.var = var;
end
function assignVar(obj,var)
obj.var = var;
end
end
end
1 commentaire
Stephen23
le 28 Juil 2023
"So is there any way can observe a variables that is outside of a function when programe run in the function?"
You could display them.
"I think it is very useful as debugging."
That is exactly what the debugging tools are for:
Those tools include e.g. DBUP and DBDOWN ,which let you step up and down the workspaces.
Réponse acceptée
Steven Lord
le 28 Juil 2023
Functions operate in their own workspaces. The variable named aValue in the workspace of the caller of assignVar is not in the workspace of the assignVar call.
The debugging tools do allow you to switch workspaces to look at variables in other functions in the call stack. See the "View Variable Value Outside Current Workspace" section on this documentation page for instructions on how to do so.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Debugging and Analysis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!