필터 지우기
필터 지우기

Is there an alternative for isstrprop to use on non integers?

조회 수: 1 (최근 30일)
Rodmehr Semnani
Rodmehr Semnani 2015년 12월 14일
댓글: Rodmehr Semnani 2016년 1월 19일
I've set up a GUI (without Guide) that first one must input parameters, and then a plot will show data. Problem is, I'm trying to find a way to check the parameters before I allow the UI to run. These parameters must be real numbers greater than 0. Using the isstrprop command works fine for positive integers, but it doesn't work when say I want to input a parameter for example 0.5 Hz.
Inside a button callback, I've inserted the following code:
try
if isstrprop(paedit.String,'digit')==1 && isstrprop(rtedit.String,'digit')==1 && isstrprop(siedit.String,'digit')==1
% accept parameters and display run button
accbtn.Visible='off';
accbtn.Enable='off';
runbtn.Visible='on';
stopbtn.Visible='on';
runbtn.Enable='on';
rtedit.Enable='off';
paedit.Enable='off';
siedit.Enable='off';
else
msgbox('Please enter a valid parameters','Input Error','error','modal');
end
catch
msgbox('Please enter a valid parameters','Input Error','error','modal');
end
This code makes sure that if a letter or a negative value is entered into one of the parameter edit boxes, it will not continue. It doesn't, however, let me do non integers. Is there a way to get around that with isstrprop or another command?

채택된 답변

Walter Roberson
Walter Roberson 2015년 12월 14일
You can use regexp(), but be careful with exponents
Really the easiest way is to use
tmp = str2double(paedit.String);
if ~isnan(tmp)
% accept parameters and display run button
accbtn.Visible='off';
accbtn.Enable='off';
runbtn.Visible='on';
stopbtn.Visible='on';
runbtn.Enable='on';
rtedit.Enable='off';
paedit.Enable='off';
siedit.Enable='off';
else
msgbox('Please enter a valid parameters','Input Error','error','modal');
end
No try/catch should be needed

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by