How to monitor a variables that is outside of a function
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
Stephen23
2023-7-28
"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.
采纳的回答
Steven Lord
2023-7-28
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Debugging and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!