Prevent changing values in GUI

23 次查看(过去 30 天)
Paramjit Yadav
Paramjit Yadav 2024-8-5,17:13
回答: Walter Roberson 2024-8-5,21:13
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
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
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.

标签

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by