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?

2 件のコメント

James116
James116 2014 年 2 月 11 日
My conclusion is that Simulink does not have this capability. Data can be written to and read from simulink.signals via data store read/write blocks or through matlab function blocks. However, this can only occur in one model and its subsystems as well as the models that it references.
If you do not have a reference to the other model in your model, you can not share the global variable between them. I will have to find another way.
sali
sali 2015 年 3 月 20 日
Hi I'm facing the same problem now, did you solve this issue? I'm trying to write the data in a file and re reread it from the other block in every simulation step!I'm not sure if this will work!

サインインしてコメントする。

回答 (1 件)

Sebastian Castro
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
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
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 ExchangeSchedule Model Components についてさらに検索

質問済み:

2014 年 2 月 10 日

コメント済み:

2022 年 4 月 22 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by