Restart a for loop with a different starting point in Matlab app designer
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Bhargavi Maganuru
le 19 Août 2019
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 commentaires
Bhargavi Maganuru
le 20 Août 2019
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').
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!