Borrar filtros
Borrar filtros

How to monitor a variables that is outside of a function

4 visualizaciones (últimos 30 días)
fa wu
fa wu el 28 de Jul. de 2023
Comentada: Walter Roberson el 29 de Jul. de 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 comentario
Stephen23
Stephen23 el 28 de Jul. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Steven Lord
Steven Lord el 28 de Jul. de 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.
  2 comentarios
fa wu
fa wu el 29 de Jul. de 2023
It is very helpful,thank you very much!
Walter Roberson
Walter Roberson el 29 de Jul. de 2023
From the command line, see dbup and dbdown for moving between active workspaces for debugging purposes.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Debugging and Analysis en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by