str = get(hObject,'String');
newValue = str2double(str);
if ~isnan(newValue)&& newValue>=-40 && newValue<=95
assignin('base','name',newValue)
else
estr = sprintf('%s is an invalid value for ... Only values allowed between -40 and 95. value is set to default (23).',str);
errordlg(estr,'Parameter Error','modal');
set(hObject,'String','23');
assignin('base','name',23);
end
This contains everything you want to know I believe. First you extract the value, then you check for validity, if it is valid you assign the value where you want ( assignin() for matlab workspace and setparam() for Simulink)
If the value is not valid, you notify the user using an error dialog and reset the value to a default.
Best regards, Dennie
Best Answer