Why aren't global variables being recognized in Simulink model explorer?

3 ビュー (過去 30 日間)
Agni Sarode
Agni Sarode 2022 年 10 月 14 日
コメント済み: Agni Sarode 2022 年 10 月 14 日
When running the dsm_demo.mdl referenced by this Mathworks documentation, global variable A is visible within the Model Explorer as a Data Store Memory object:
When I replicate the MATLAB function used in this model using a global variable B, it is not recognized in the Model Explorer:
Similarly, the Ports and Data Manager for "MATLAB Function" (the provided function) shows A as a data object, while the Ports and Data Manager for "MATLAB Function1" (replicated function) does not show B as a data object.
The MATLAB function used in the model, compared to the one I created are the exact same:
Provided MATLAB function (denoted by "MATLAB Function"):
function y = fcn
%#codegen
global A;
A = A+1;
y = A;
Replicated MATLAB function (denoted by "MATLAB Function1"):
function y = fcn
%#codegen
global B;
B = B+1;
y = B;
I've specifed the Data Type and the Signal Type as the same as with the model's global variable A (data type is double, signal type is real).
When running this model the error messages received are as shown:
Has anyone else seen this issue? Any help would be appreciated!

採用された回答

Fangjun Jiang
Fangjun Jiang 2022 年 10 月 14 日
Double click "MATLAB Function1" to open the Editor, click "Edit Data" button, add data "B" as a "Data Store Memory".
  3 件のコメント
Fangjun Jiang
Fangjun Jiang 2022 年 10 月 14 日
編集済み: Fangjun Jiang 2022 年 10 月 14 日
Not sure. It seems that if you change the function arguments fcn(x,y,z), x,y and z are automatically reflected in the Ports and Data Manager. But since global variable does not appear in the function arguments, you have to manage it directly in the Ports and Data Manager.
Agni Sarode
Agni Sarode 2022 年 10 月 14 日
Understood. Seems like the demo model may have already initialized the global variable A in the Ports and Data Manager. But this page fails to mention to do the same when the user is creating their own.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by