Share data between multiple Simulink models? (Global simulink signals)
이전 댓글 표시
I have normal and external models that I can not combine, so I wish to pass a variable between them.
If anyone has an example of using simulink signals and matlab function blocks to do this, I would like to see it.
This is how I have attempted it so far:
First, I define a simulink.signal object in the base workspace, with all the proper parameters as specified here: http://www.mathworks.com/help/simulink/ug/using-global-data-with-the-matlab-function-block.html
I add a matlab function block to my diagram. I register the simulink signal with a global variable in this function block. The values going into the function are stored into the signal.
function fcn(x)
global A;
A = x;
I then create another matlab function in the other model and do the same thing, this time taking the variable out of the signal.
function y = fcn()
global A;
y=A;
When I run everything, the values don't get passed through. The output just gets the initial value of the simulink signal.
Am I doing this right?
답변 (1개)
Sebastian Castro
2015년 3월 21일
1 개 추천
Simulink does have this capability... either using global variables in a MATLAB Function block or using Data Store Read/Write blocks and Simulink Signals.
댓글 수: 2
kevin hugh
2017년 10월 28일
will this solution carry over when the models are compiled to standalone executables? Or does it require to be run in the matlab environment?
Heaven winds
2022년 4월 22일
I have this problem recently. And tried this solution. It can only worked in the same one session. If you run two sessions separately. It will not work.
카테고리
도움말 센터 및 File Exchange에서 Event Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!