Move to next and previous iteration in for loop on button press

조회 수: 3 (최근 30일)
Konvictus177
Konvictus177 2021년 10월 13일
편집: Konvictus177 2021년 10월 13일
Hello,
I am playing a video inside a for loop (for frame = startframe:endframe) and the image updates for each iteration in the for loop.
I want the user to be able to move forward and backward inside the loop depending on which button is pressed. Say "left arrow key" moves to previous iteration and "right arrow key" moves to next iteration.
How can I do this?
Thanks!

답변 (1개)

KSSV
KSSV 2021년 10월 13일
%Right
for i = 1:10
fprintf('%d\n',i)
end
1 2 3 4 5 6 7 8 9 10
% Left
for i = 10:-1:1
fprintf('%d\n',i)
end
10 9 8 7 6 5 4 3 2 1
  댓글 수: 3
KSSV
KSSV 2021년 10월 13일
When you press the button get the values or some number and then decide whether to go left or right.
Konvictus177
Konvictus177 2021년 10월 13일
How would I change within the loop. Let's say I am at index 40 in my loop and now I want to go left 39,38,37 now I want to go right again 38,39,40, etc.
Can you show an example?
Thanks.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by