How to monitor a variables that is outside of a function

조회 수: 6 (최근 30일)
fa wu
fa wu 2023년 7월 28일
댓글: Walter Roberson 2023년 7월 29일
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
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
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.
  댓글 수: 2
fa wu
fa wu 2023년 7월 29일
It is very helpful,thank you very much!
Walter Roberson
Walter Roberson 2023년 7월 29일
From the command line, see dbup and dbdown for moving between active workspaces for debugging purposes.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by