How to make Simulink read a MatLab variable every 5 seconds?
Show older comments
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?
Accepted Answer
More Answers (2)
Fangjun Jiang
on 14 Sep 2023
0 votes
Use the "MATLAB Function" block to integrate your MATLAB algorithem directly into a Simulink model.
1 Comment
Felipe Teixeira Roberto
on 14 Sep 2023
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 Comments
Felipe Teixeira Roberto
on 14 Sep 2023
Guillaume
on 15 Sep 2023
You are very welcome Felipe :-) Welcome in this nice community !
Categories
Find more on Event Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!