![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1758674/image.gif)
Variable Window Not Updating Automatically when code is executed
46 views (last 30 days)
Show older comments
When I run some code which changes the contents of a class in my workspace, that change isn't showing in the variables window unless I close this property and re-open it in the variables window. As you can see, when I quirry what this value is in the command prompt, I see that it doesn't match the varibles window.
How is the "variables window" getting updated? Are there some settings in Matlab to adjust if the variables window automatically updates itselft on a perioidic basis, like once every 500mS or something? I don't recall ever experiencing this before.
Please note that this array that I am looking at in the screenshot below, is an array of an enumeration class, where 'SK1' in the command window corelates to 1.0000 in the variables window.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1758209/image.png)
0 Comments
Answers (1)
Subhajyoti
on 23 Aug 2024 at 12:46
Hi @Cody Brown
The MATLAB "Variables" window updates its contents whenever a script or function has finished executing, rather than on a periodic basis during execution. This means that the variable values are refreshed once the script completes, rather than continuously every few milliseconds. Here's a GIF demonstrating the expected behaviour:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1758674/image.gif)
Below is the sample class and test functions I used to explore this:
‘sampleClass.m’:
classdef sampleClass
properties (SetAccess = private)
prop1 = 0;
prop2 = 0;
end
methods (Access = public)
function obj = setProps(obj, val)
obj.prop1 = val*2;
obj.prop2 = val*val;
end
function getProps(obj)
fprintf('prop1: %d\n', obj.prop1);
fprintf('prop2: %d\n', obj.prop2);
end
end
end
‘testFunction.m’:
obj = sampleClass;
obj = testFunction(obj, 3);
pause(0.000001)
obj = testFunction(obj, 5);
pause(0.001);
obj = testFunction(obj, 11);
pause(1);
function obj = testFunction(obj, value)
% Set the properties
obj = obj.setProps(value);
% Get the properties
obj.getProps();
end
This test function demonstrates how the "Variables" window updates after the script execution.
You may go through the following MathWorks documentation links to learn more about ‘Workspace and Variable Preferences’:
1 Comment
See Also
Categories
Find more on Enumerations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!