Initializing discrete states with Matlab functions
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
retigi
am 5 Jul. 2018
Beantwortet: Mark McBroom
am 5 Jul. 2018
I have the following hypothetical system:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/191676/image.png)
The discrete delay element uses input port to initialize its state when enabled. When I check the system steps in debug mode I realized that simulink continue to execute/output "matlab function" even after the delay element is initialized properly. Therefore simulink simply wastes computational power for no reason during simulation phase.
Is there a way to disable the matlab function block after the discrete delay is initialized?
0 Kommentare
Akzeptierte Antwort
Mark McBroom
am 5 Jul. 2018
If you have a newer version of MATLAB, you can place your MATLAB Function block in a Simulink Initialize Function block as described here .
Alternately, you can use a pattern similar to the following to enable the MATLAB function for the first timestep only:
1. Put matlab fcn block into an enabled SS 2. Insert a constant block with value of zero, connect that to a unit delay block ( with initial value set to one) and then connect the unit delay block to the enabled SS. This should then only execute your matlab fcn block at init and t+1. It should be disabled for all subsequent time steps.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Sources finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!