How to run a Simulink Model (.slx) and while loop in (.m file) simultaneously?

7 visualizaciones (últimos 30 días)
Hi clever people of the Matlab World,
I came across the following problem and I would greatly appreciate any help/suggestions.
What I built: I have a GUI in which I have implemented a simple state machine. This state machine is being executed in a while loop until a user input stops the loop. The constant refreshing (use of the loop) is necessary, because Audio data gets imported from a ring buffer and manipulated. The GUI runs nicely and stable.
What I want: As an extension to the usability of this tool, I need to run a Simulink model (for inf time) while the while-loop in the gui (.m file) is also running. Common variables for the gui and Simulink has been established and tested.
What the problem is: The Simulink model is being started and runs. As soon as the while loop in the gui (.m file) starts, the Simulink model is not proceeding in time, i.e. the execution time T=... freezes but the "Pause" and "Stop" button still are clickable.
What I tried: Open two instances of MATLAB and try to connect the two instances via the extension "sharedmatrix" by Joshua Dillon. The installation however was unsuccessful. An option I see but dont like is let the two Matlab sessions communicate over I/O files. I also had a look into parpool (Parallel Computing Toolbox) but I reckon this is not really suitable here.
In a nutshell: Is there a way to execute a while loop in a .m file for an unspecified time (until the user stops it) AND let a Simulink model run simultaneously? If not, what are the workarounds?
Thank you very much in advance for spreading ideas and helping me out on this one.

Respuestas (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 1 de Jun. de 2021
This is the general syntax to simulate Simulink model with a loop, e.g:
for ii=1:N
OUT(ii)=sim('ABC.slx');
end
  3 comentarios
Sulaymon Eshkabilov
Sulaymon Eshkabilov el 2 de Jun. de 2021
A sample model ABC.slx contains [To Workspace] block that exports the simulation data to MATLAB workspace.
The rest works just as given in the above code in MATLAB environment.
anas radwan
anas radwan el 2 de Jun. de 2021
To workspace data is available only when simulation is finished.... My simulation is control loop which I need to get data while it's running, my code is
load_system('simulinkstatespacemodel')
set_param('simulinkstatespacemodel', 'SimulationCommand', 'start')
block = 'simulinkstatespacemodel/Variable Pulse Generator';
while True
rto = get_param(block, 'RuntimeObject');
pulsevalue = rto.OutputPort(1).Data
end
but once the code enters the loop it stops the simulation on simulink.
what i want is to keep the simulink running and take the output in real time

Iniciar sesión para comentar.

Categorías

Más información sobre General Applications en Help Center y File Exchange.

Productos


Versión

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by