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?