Restart a for loop with a different starting point in Matlab app designer

조회 수: 2 (최근 30일)
Hi,
I have attached an app (vapp1.mlapp) which displays 'Display 1, 2, 3...10' for each iteration when Begin button is pushed.
I wanted to repeat a particular iteration and then complete the iterations till the end (10). For example, after Begin button is pushed, suppose currently the display is 'Display 6', I want to restart the display with 'Display 5' and go upto 'Display 10' when I push Restart from Last Step Button (It uses return function).
The repeat function works fine, but after displaying upto the end of the iteration ('Display 10'), it completes the iterations which were stopped when Restart from Last Step Button was pushed.
In the example, what I want is to display 'Display 1' to 'Display 6' and then after pressing Restart from Last Step, dispaly 'Display 5' to 'Display 10' and then stop. But after displaying 'Display 10' it starts displaying from 'Display 7' to 'Display 10'.
Kindly suggest a solution.

채택된 답변

Bhargavi Maganuru
Bhargavi Maganuru 2019년 8월 19일
You can use flag variable to stop the execution of BeginButtonPushed function in your code after pressing Restart from Last Step button.
Add following lines of code:
Add global variable named flag in all the functions: global flag;
In line 35,44 add: flag=0;
In line 53 add: flag=1;
In line 18, modify the if condition to: if (repeat==1 || flag==1)
Hope this helps.
  댓글 수: 4
Bhargavi Maganuru
Bhargavi Maganuru 2019년 8월 20일
Hi,
When you press Begin button,the function BeginButtonPushed will starts execution and now when you press Restart from Last Step button(say at 'Display 6'), the function RepeatLastStepButtonPushed will complete execution( displays 'Display 5' to 'Display 10'), now Displayy function called in BeginButtonPushed will still continue to execute from where it got paused(displays 'Display 7' to 'Display 10').
Sudhee
Sudhee 2019년 8월 20일
In your answer,
''....now Displayy function called in BeginButtonPushed will still continue to execute from where it got paused(displays 'Display 7' to 'Display 10').'',
isn't the return function supposed to exit the for loop rather than just pause it?
Regards

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by