for loop forward and backward

5 ビュー (過去 30 日間)
Rightia Rollmann
Rightia Rollmann 2017 年 1 月 12 日
編集済み: Luke M 2017 年 1 月 12 日
How to make the loop below count increasingly (1,2,3,…) when I press the mouse button and count decreasingly (4,3,2,…) when if press a keyboard button?
for i = 1:10
disp( num2str( i ) );
w = waitforbuttonpress;
end
  2 件のコメント
John Chilleri
John Chilleri 2017 年 1 月 12 日
This can be done with buttons created in a GUI, would that be adequate?
Rightia Rollmann
Rightia Rollmann 2017 年 1 月 12 日
I want the simplest soloution where no GUI is needed

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

採用された回答

Luke M
Luke M 2017 年 1 月 12 日
編集済み: Luke M 2017 年 1 月 12 日
I'm not sure if it can be done in a for loop, but in a while loop:
i = 1;
while i >= 1 && i <= 10
disp( num2str( i ) );
if waitforbuttonpress
i = i - 1;
else
i = i + 1;
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by