Restart a for loop with a different starting point in Matlab app designer
1 次查看(过去 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.
0 个评论
采纳的回答
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
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').
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!