How to make Simulink read a MatLab variable every 5 seconds?
이전 댓글 표시
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?
채택된 답변
추가 답변 (2개)
Fangjun Jiang
2023년 9월 14일
0 개 추천
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
Felipe Teixeira Roberto
2023년 9월 14일
Guillaume
2023년 9월 15일
You are very welcome Felipe :-) Welcome in this nice community !
카테고리
도움말 센터 및 File Exchange에서 Sources에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!