Problem with waitforbuttonpress and if command

6 views (last 30 days)
Hi! I'm doing a matlab programs and I have a litle problem.
I want to open a number in a random form, but at the same time I want that matlab evaluate if exist an input from the keyboard. So, if I press a key, matlab reboot the loop 'for', but if I don´t press any key, matlab open the number, and so on.
For this reason, I'm using the comand 'if', but I have so many problems to advance it. I had used the 'switch' comand, but it give the same problem.
If anyone can help me.
My code is the next:
n=6; %number of repetitions of mi loop
for i = 1:n;
% Here, I want to have the 2 options, one that allows me to reboot the loop if i press any key, and another that give me a random number when no-press any key
if senal = waitforbuttonpress || getkey
continue %With this, the loop reboot
else
i=randperm(3,1); %It give a random number
disp(i)
pause(1)
end
end
Thanks for all!

Accepted Answer

Walter Roberson
Walter Roberson on 23 Apr 2013
Button? Or keyboard key? getkey() is keyboard.

More Answers (0)

Categories

Find more on Desktop in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!