Pause and resume a MATLAB Simulation

23 visualizaciones (últimos 30 días)
Karthikeyan Deivamani
Karthikeyan Deivamani el 15 de Oct. de 2021
Editada: Karthikeyan Deivamani el 21 de Oct. de 2021
I am trying to pause the simulation of cars with a space key input and again resume the simulation when a space key is pressed. I have tried using waitforbuttonpress and pause function but it pauses but does not resume. This has to come inside a while loop to wait for the buttonpress and check if it is space.

Respuestas (1)

Pavan Guntha
Pavan Guntha el 20 de Oct. de 2021
Hello Karthikeyan,
In order to pause a simulation upon occurance of an event, callbacks can be leveraged. In this scenario the simulation needs to be paused once 'space' bar is pressed. You could use 'WindowKeyPressFcn' callback of the figure block in order to detect whether the space bar is pressed or not and there by pause the simulation. The callback can be written as follows:
function buttonCallback(src, event)
val=event.Key; % Key property contains the details of the key which was pressed
if val=='space'
disp('Space Pressed. Pausing...')
pause(5)
end
end
The modified code is attached. For more information regarding callbacks you could have a look at the following documentation page: Callbacks Documentation.
Hope this helps!
  1 comentario
Karthikeyan Deivamani
Karthikeyan Deivamani el 21 de Oct. de 2021
Editada: Karthikeyan Deivamani el 21 de Oct. de 2021
Hi pavan,
Thanks a lot,this is very helpful . I had difficulty figuring my way around uicontrol now it's better.
Thanks and regards,
Karthikeyan Deivamani

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by