How to run a MATLAB Script once for each Simulink Loop.
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kieran McMullen
el 28 de Jun. de 2020
Comentada: rubindan
el 1 de Jul. de 2020
I'm trying to build a Simulink model that tracks the instantaneous position of a 6DOF dynamic mechanical system, based on a series of inputs which are 6x6 matrices (which describe behaviour), 1x6 vectors (intial) and one time-dependent impulse (a simulated impact), and with an ouput of a 1x6 matrix describing the position of one element in all the degrees of freedom, which should be plotted over time as the simulation runs.
Currently I calculate the forces acting on the system using an equation, which requires an Add Block, and a subsequent Matrix Multiply block to remove mass and inertia and get the acceleration.
My problem is that some of these matrices change with position and velocity (specifically related to inertia and coriolis forces), but I use a toolbox to generate them, so a direct translation into Simulink is not possible.
As I use a MATLAB script to set up these matrices, I thought I could just change the instantaenous position and velocity using the To Workspace Block from the simulaiton outputs and run the script again before each simulation.
I currently can't find a way to get this to work as all the Blocks I've seen so far require problematic conditions. Interpreted MATLAB Fcn runs specific functions with defined inputs and outputs, but I'd like to run the whole script based on the output of the previous loop. Stop Fcn will only run the code when the simulation has ended, but I want to follow the position over many loops until it converges.
Is there any way to do this? Run a simulation that switches between Simulink flow and MATLAB script and back with each loop?
0 comentarios
Respuesta aceptada
rubindan
el 29 de Jun. de 2020
In you case inputs to the block will be the instantaenous position and velocity, and outputds will be the computed matrices.
2 comentarios
rubindan
el 1 de Jul. de 2020
You can either specify the dimensions of inputs and outputs explicitly in the Ports and Data Manager, or preallocate them using e.g. zeros(6,6) before doing the computations.
Más respuestas (0)
Ver también
Categorías
Más información sobre General Applications en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!