Variable Window Not Updating Automatically when code is executed
25 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Subhajyoti
2024-8-23
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:
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’:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Enumerations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!