Problem with a callback function that checks user input
이전 댓글 표시
I have an edit box and I want that another uicontrol changes its color depending on user input. I have defined a callback function that should control that, but my problem is when the user input a negative value between the valid range because takes "-" as an invalid input.
function check(hObject,~)
inp = get(hObject,'String');
if ~isempty(strfind(inp,','))
warndlg('Invalid input. No commas are allowed','Warning');
set(tex,'BackgroundColor',[.91 .88 .88]);
elseif ~isempty(regexp(inp,'\D','once'))
warndlg('Invalid input. Only numbers are allowed','Warning');
set(tex,'BackgroundColor',[.91 .88 .88]);
elseif str2num(inp)<-360 || str2num(inp)>360
warndlg('RANGE ERROR. Valid values are between -360° and 360°','Warning');
set(tex,'BackgroundColor',[.91 .88 .88]);
elseif str2num(inp)>-360 && str2num(inp)<360
set(tex,'BackgroundColor',[.88 .91 .88])
end
end
So what can I do to solve this?
채택된 답변
추가 답변 (1개)
카테고리
도움말 센터 및 File Exchange에서 App Building에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!