How to make Simulink read a MatLab variable every 5 seconds?
Afficher commentaires plus anciens
Let's assume a simple logic in MatLab that, every 5 seconds the variable ' i ' is increased to '+1' in a inf while loop.
Is it possible to use the ' i ' as input in a Simulink paced simulation in a way that the value is constantly been updated while the MatLab code is running?
Réponse acceptée
Plus de réponses (2)
Fangjun Jiang
le 14 Sep 2023
0 votes
Use the "MATLAB Function" block to integrate your MATLAB algorithem directly into a Simulink model.
Hello,
In Simulink you can use a Constant block or any other block that reads a Workspace variable value.
In your Matlab function you could then change the value of this variable using:
assignin('base', 'i', i+1);
Hope this helps.
As pointed by @Jon, this will not work because Simulink will not actualize the variable value during simulation. So you should use the set_param method.
2 commentaires
Felipe Teixeira Roberto
le 14 Sep 2023
Guillaume
le 15 Sep 2023
You are very welcome Felipe :-) Welcome in this nice community !
Catégories
En savoir plus sur Event Functions dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!