フィルターのクリア

How to display an error message with Try/catch?

7 ビュー (過去 30 日間)
anahita
anahita 2013 年 7 月 2 日
Hi
I am a complete newbie. I have created a GUI, and in this GUI at the first the user should choose a video to load, after that he should enter a number(of frame) for visualising the photo of this frame. I want to use a try/catch who doesn't let the user to enter a number which is superior than the existing number of frames and display an error message. But I don't know how to do that...( The user can choose any video at the first, so I won't know the number of frames. How should I specify the range of the numbers that he can enter? I know that it could be with the size() but I don't know how...)
  1 件のコメント
Image Analyst
Image Analyst 2013 年 7 月 2 日
編集済み: Image Analyst 2013 年 7 月 2 日
You already asked this twice before, and accepted my answer in this post - what's different now?

サインインしてコメントする。

採用された回答

Sean de Wolski
Sean de Wolski 2013 年 7 月 2 日
編集済み: Sean de Wolski 2013 年 7 月 2 日
Instead of using a try/catch, inside of the callback for the edit box where they enter the number figure out if the value they have entered is accurate. If it's not, write back the previous value and use errordlg to display the error message.
More
function exampleVerifyString
uicontrol('Style','edit',...
'Units','normalized',...
'Position',[0.1 0.1 0.3 0.5],...
'String','5',...
'Callback',@verifyString);
end
function verifyString(src,~)
%Get the string
val = str2double(get(src,'String'));
%If it's not a number, or integerbetween 0 and 100
if isnan(val) || val<0 || val>100 || val ~= round(val)
set(src,'String','5');
errordlg('Please enter an integer between 0 and 100','Invalid Input');
end
end
Save the above as exampleVerifyString.m
  2 件のコメント
anahita
anahita 2013 年 7 月 2 日
編集済み: anahita 2013 年 7 月 3 日
Thank you soooooooo much for the answer.
Sean de Wolski
Sean de Wolski 2013 年 7 月 2 日
See more

サインインしてコメントする。

その他の回答 (1 件)

Chandrasekhar
Chandrasekhar 2013 年 7 月 2 日
try
% code in try part
catch
errordlg('error')
end

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by