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);
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: