[HELP] required for exception handling during user input
信息
此问题已关闭。 请重新打开它进行编辑或回答。
显示 更早的评论
Hi need help!
I need to capture user input using getkey(). However the user is only allowed to enter values between 1 and 9. If user presses something else it should wait (can give an error message too) for the user to press a valid key (1-9).
Code please.
Thanks in anticipation.
0 个评论
回答(2 个)
Sean de Wolski
2012-1-12
what is getkey()?
docsearch getkey
doesn't return any results. If you want the keypressfcn of a figure to perform this test, here is a small demo:
All in one file ans_keypressexample.m
function ans_keypressexample
figure('keypressfcn',@clicked); %make a figure
function clicked(~,evt)
key = str2double(evt.Key); %get the key
if isnan(key)||key==0 %is it between 1 and 9?
error('Booo!'); %no :(
else
disp('yay!!');
end
1 个评论
helpseeker
2012-1-12
Walter Roberson
2012-1-12
0 个投票
As you are using a File Exchange contribution, edit the source for your own purposes. http://www.mathworks.com/matlabcentral/fileexchange/7465-getkey
0 个评论
此问题已关闭。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!