Prevent changing values in GUI
23 次查看(过去 30 天)
显示 更早的评论
Dear firends,
I have a querry reagrding the GUI formation in MATLAB. I have made a GUI and everything is ok but the values of tab inside the listerner called as 'angle' can be changed with edit filed and slider, which has limit obj.angle = [-10,10].
During static code given below also I have made the condtion 'if (obj.angle ~= obj.angle) & obj.angle<10 & obj.angle>-10'. Hence the static code is not executed if the slider and editfield is out of range of given limit.
But the problem is if I go inside the angle.Value and write some number not in range or limit of angle then even though the static code is not excuted but the value inside angle.Value is updated and stored. I dont want this.
Hence, I request to please suggest some way by which I can prevent the value from being updated manually inside the angle.Value. And the angle.Value should have the same limit as it has when input is given through slider or edit field.
I request to please help.
Thanking all,
Kind regards
classdef classErowin < handle
properties
fig
serial_port
UI
angle
end
properties (SetObservable, AbortSet) % for listeners
angle
end
methods
function obj = class() % constructor
obj.angle = [-10,10]
edit_filed
slider
end
end
methods (Static)
function handlePropEvents(src,evnt)
obj = evnt.AffectedObject;
switch src.Name
case {'angle'}
if (obj.angle ~= obj.angle) & obj.angle<10 & obj.angle>-10
end
end
end
end
end
1 个评论
VBBV
2024-8-5,20:07
@Paramjit Yadav you could try setting the default value for angle as empty inside the static function
if (obj.angle ~= obj.angle) & obj.angle<10 & obj.angle>-10
angle.Value = [] % set the value default value
end
回答(1 个)
Walter Roberson
2024-8-5,21:13
But the problem is if I go inside the angle.Value and write some number not in range or limit of angle then even though the static code is not excuted but the value inside angle.Value is updated and stored.
You need a set function https://www.mathworks.com/help/matlab/matlab_oop/property-set-methods.html#buq4ila-1
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!