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

2 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Bhargavi Maganuru
Bhargavi Maganuru el 19 de Ag. de 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 comentarios
Bhargavi Maganuru
Bhargavi Maganuru el 20 de Ag. de 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').
Sudhee
Sudhee el 20 de Ag. de 2019
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by