How to monitor a variables that is outside of a function
조회 수: 6 (최근 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!