Opening simulink model in separate processor thread

Hello all,
I have a simulink model that have interactive features, like push buttons and switch sliders. I want to simulate this model during a script and then collect the generated data and use in sequence, but I got stuck in how to make my main script wait for this model without blocking the simulink GUI and simulation.
My first try was to create a variable 'simulation_flag' and set it to 0 when the simulink simulation is done, like in the code below:
open_system(my_model);
simulation_flag = 1;
while(simulation_flag)
end;
However, this piece of code make my simulink window unresponsible.
My second try was to add a pause in the while loop
open_system(my_model);
simulation_flag = 1;
while(simulation_flag)
pause(0.01)
end;
In this case, the simulation runs, but the interactive features (buttons and etc) did not work.
I understood that there is a processor concurrence between my main script (locked in the while loop) and the simulation/GUI of my Simulink model. So, I think that my solution would be to open my model GUI in a separated matlab thread. To do it, i tried the following:
First try:
model_job = batch(open_system(my_model));
Got the error: Too many output arguments
Second try:
model_job = batch(my_model);
The "secondy try" pops up the simulink model, but it lasts for a fell moments and then it closes. This makes me fell more close to the solution, but I would like that the GUI doesn't get closed automatically.
How could I address this problem? When I run the second try command and the model GUI pops up and close, it means that the thread gets finished or it is hidden? Is possible to unhide this window?
Just to reinforce: I need my model GUI, so I can run the simulation interactively. The solutions that only triggers the simulation in parallel with my main script won't work for me, unfortunatelly.
Thanks

Respuestas (0)

Categorías

Preguntada:

el 17 de Abr. de 2019

Editada:

el 17 de Abr. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by