Calculate stuff during Simulink-Simulation

3 vues (au cours des 30 derniers jours)
MarinoM
MarinoM le 2 Sep 2018
Hi,
I have a model of a back-to-back converter, out of which I'm sending two variables to my Matlab workspace (the last 200.000 values, since with the sample time of 0.0000001s it is only all the values from a complete period). I run the simulation once, and then I have two variables in my workspace. I'm using these variables as vector and I'm calculating a few things with them, like calculating the RMS of one and taking the Max value minus the min value of the other vector, and a bit more and giving these two single (!) values that I get into another Matlab Function that returns one value.
Now I want that to happen on the go, during a Simulation (Tsim = inf). I know that I can pause a Simulation, calculate and then continue, but is there an option to do all this on the go?
The Matlab Function block seems to be the right way, but I have the problem that I need the last 200.000 values of a current, not only the one current value of it.
So how do I save 200.000 values into a vector, inside a Matlab-Function-Block to use them in real (simulation) time? I don't want to do anything with the result of the Function, only display it.
Doing all the calculations in Simulink Blocks doesn't seem to be a good way either, especially since I need one RMS Value of the current, which is not working because of some error because of the sample time...

Réponses (1)

Sara Nadeau
Sara Nadeau le 4 Sep 2018
What version of Simulink are you working with? In 18a, you can use the Data Access feature to process logged signal data during simulation. You would write a callback function to specify in the Instrumentation Properties for your logged signal. The callback would handle selecting and/or accumulating the samples and then calculating the RMS value. You could use the assignin function to display the calculated results in the MATLAB workspace.

Community Treasure Hunt

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

Start Hunting!

Translated by