MATLAB: How to see the variables in base workspace when I am in a function

basecallerdebugevalinMATLABmodescopeworkspace

I set a break point in my function and I would like to see the variables in the base workspace (For debug purpose).
I am using MATLAB R2018b. In previous releases, I remember there was a button on the workspace panel that I can switch the view from function scope to base scope.
However, this button is no longer there.

Best Answer

I use the example code below to demonstrate two methods which shows 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 stop before the line 'display(X)', and execute the main.m file. When MATLAB enter the debug mode, the current workspace is in fun2 scope.
To view the variables in the base scope in the debug mode, please try the follow methods:
Method 1. Programmatic way:
evalin('base','who')
evalin('base','whos')
MATLAB will show the output like:
Method 2. GUI way:
In early release 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 release such as R2018a, you can find this button in the editor toolstrip.