input = str2num(get(hObject,'String'));if (isempty(input)) set(hObject,'String','1') warndlg('Input must be numerical');endx = get(hObject,'String'); % get text from handles structure
try y = x{1}; % cell to string
z = str2num(strtok(y)); % string to number
catch z = str2num(strtok(x)); % string to numberendlower_limit = 1;upper_limit = 2000;%Output equals value of z if z falls between the bounds set by lower_limit
%and upper_limit. Otherwise it is 0 or an empty array
output = z*(z < upper_limit)*(z > lower_limit);%If z does not fall within the bounds set by the limit parameters or is an
%empty array
if isempty(output) | (~output) %Set the output value to the limit value closest to z
output = lower_limit*(z < lower_limit) + upper_limit*(z > upper_limit); %If there is no value in z, set the output value to the lower limit of
%the desired bounds
if isempty(output) output = lower_limit; end %Create a message string and initiate a message box informing the user
%to enter a value within the limits of the defined range
str = sprintf('Enter a number between %d and %d', lower_limit, upper_limit); msgbox(str);end%Set the value of the text box to the new value, which lies within the
%value range
set(hObject,'String',{num2str(output(1))}); set(0,'ShowHiddenHandles','on');handles=guidata(hObject);val=get(hObject,'string');%put the value to text
set(handles.edit_period,'string',val);set(handles.slider_period,'value',str2double(val));%Update SIM model
set_param('DCDCconverter/Enabled Subsystem/period','value',num2str(val));set_param('DCDCconverter/Enabled Subsystem1/period1','value',num2str(val));set_param('DCDCconverter/Enabled Subsystem2/period2','value',num2str(val));set_param('DCDCconverter/Enabled Subsystem3/period','value',num2str(val));guidata(hObject,handles);
MATLAB: I am newbei matlab coder. i want to put a limit range in gui edit text and also want to update this value in simulink model i dit it but the value didn’t update when i enter the value in edit text????? Any help is appreaciable….
gui edit textMATLAB and Simulink Student Suite
Best Answer