How to make a value limit condition to a edit text and slider in GUI?
Ältere Kommentare anzeigen
I made a GUI that contains 1 slider (min=-180,max=180) and 1 edit text my goal is to have the user type the angle wanted in the edit text or instead use the slider to choose a value. but i found a problem: if the user typed a value bigger than 180 or smaller than -180, the slider vanishes.. I want to show a pop error window when that happens and reset the value of the edit text and the slider to max (or min) value .. I've wrote a code, but it seems that it's not working:
function Valeur_Theta1_Callback(hObject, eventdata, handles)
% hObject handle to Valeur_Theta1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Valeur_Theta1 as text
% str2double(get(hObject,'String')) returns contents of Valeur_Theta1 as a double
clear min max Theta1;
min=-180;max=180;
Theta1=str2double(get(handles.Valeur_Theta1,'string'));
if(Theta1>-180 || Theta1<180)
{
set(handles.Slider_Theta1,'value',Theta1);}
else if(Theta1<-180)
{
msgbox('Invalid Value', 'Error','error');
set(handles.Slider_Theta1,'value',min);
set(handles.Valeur_Theta1,'string',min);
}
else if(Theta1<-180)
{
msgbox('Invalid Value', 'Error','error');
set(handles.Slider_Theta1,'value',max);
set(handles.Valeur_Theta1,'string',max);
}
end
end
end
please help!
Akzeptierte Antwort
Weitere Antworten (1)
Med Aymane Ahajjam
am 6 Sep. 2015
0 Stimmen
Kategorien
Mehr zu Variables finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!