Error Messages
이전 댓글 표시
Hi Folks,
I have generated my code depending on what the user inputs. So, my questions in the command window is basically numbers corresponding to particular Methods that I have coded. However, now, if the user inputs a character or number outside those input number range the question asks, by mistake, the code continues and gives an error later down. I would like it to stop there temperarily and requestion the user with the same question until he/she gets it correct.
disp('Please Enter the Method:')
disp('1 – Aligrot Method')
disp('2 – Pishinger Method')
disp('3 – Watson Method')
UserInput = input('Enter the Number corresponding to the selective Method and Press ENTER: ');
if UserInput == 1
… %calls a set of functions
elseif UserInput == 2
… %calls a set of functions
elseif UserInput == 3
… %calls a set of functions
elseif 3 < UserInput < 1 || ischar(UserInput )
error('PLEASE READ CAREFULLY!!');
end
Thanks
댓글 수: 2
Daniel Shub
2012년 4월 26일
What is the problem you are having? What happens and what do you expect to happen?
Ferd
2012년 4월 26일
채택된 답변
추가 답변 (1개)
Daniel Shub
2012년 4월 26일
Why not get fancy:
UserInput = questdlg('Select a method.', 'Method List', ...
'Aligrot', 'Pishinger', 'Watson', 'Aligrot')
switch lower(UserInput)
case 'aligrot' %calls a set of functions
case 'pishinger' %calls a set of functions
case 'Watson' %calls a set of functions
end
댓글 수: 7
Ferd
2012년 4월 26일
Ferd
2012년 4월 26일
Walter Roberson
2012년 4월 26일
What would you like an "analog meter inputdialog box" to look like?
Image Analyst
2012년 4월 26일
For more than 3 items, you can have a popup dialog box with a vertical array of buttons by using the menu() function. It returns the number of the button you clicked on and then you can check that button number with an if or switch statement.
Ferd
2012년 4월 26일
Walter Roberson
2012년 4월 26일
Everything in the graphics system is a GUI, including inputdialog. Some of the GUI are pre-written, that's all.
I do not recall any pre-written sliders at the moment, but sliders are not difficult to implement. You might want to check out (e.g.) "41 GUI examples" from the file exchange.
Ferd
2012년 4월 27일
카테고리
도움말 센터 및 File Exchange에서 App Building에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!