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

18 views (last 30 days)
I set a breakpoint in my function and I would like to see the variables in the base workspace (for debugging purposes).

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 15 Jun 2023
Edited: MathWorks Support Team on 15 Jun 2023
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:

More Answers (1)

Stephen23
Stephen23 on 30 Aug 2019
Method 3: dbup and dbdown.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!