How do I see the variables in base workspace when I am in a function?

18 次查看(过去 30 天)
I set a breakpoint in my function and I would like to see the variables in the base workspace (for debugging purposes).

采纳的回答

MathWorks Support Team
编辑:MathWorks Support Team 2023-6-15
The example code below is used to demonstrate two methods to see variables in the base workspace:
% ==================
main.m
% ==================
a=1;
X=10;
fun1(X);
% ==================
fun1.m
% ==================
function fun1(X)
b=2;
fun2(X);
end
function fun2(X)
c=3;
display(X); % set a break point at the beginning of this line
end
Set a break point in fun2 to force MATLAB to stop before the line 'display(X)', and execute the main.m file. When MATLAB enters the debug mode, the current workspace is in fun2 scope.
To view the variables in the base scope in the debug mode, please try one of the following methods:
Method 1. Programmatic way:
evalin('base','who')
evalin('base','whos')
MATLAB will show the output as follows:
Method 2. GUI way:
In earlier releases such as R2009a, there is a button on the workspace panel that can be used to change the scope view to the base scope.
In newer releases such as R2018a, you can find this button in the Editor tab in the toolstrip:

更多回答(1 个)

Stephen23
Stephen23 2019-8-30
Method 3: dbup and dbdown.

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by