How can I access to the Model Workspace from my Simulink file from a Matlab function block

35 ビュー (過去 30 日間)
Pablo Díez
Pablo Díez 2020 年 3 月 20 日
コメント済み: FEDERICO 2023 年 3 月 24 日
I have created a function in a .m file which is used in a Matlab Function Block inside a Simulink model. There is a parameter that the .m function uses which is created in the Model Workspace, since it is impossible to connect that variable to a constant block, how can I access to the Model Workspace to extract the variable I want for my .m function?
  3 件のコメント
Pablo Díez
Pablo Díez 2021 年 2 月 2 日
Hi Laurenz,
Yes, you need to define the Model Workspace.
Then, use getVariable to extract the variables you want.
Dimuthu Arachchige
Dimuthu Arachchige 2022 年 6 月 6 日
getVariable is not identified in the Matlab function block in simulink. Also the workspace varible. How to solve these issues?

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

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2022 年 6 月 6 日
In the MATLAB Function block, click "edit data", add a data "MyVar", specify it as a "parameter" of the MATLAB Function block.
In the Simulink model's "Model Workspace", make sure there is a variable called "MyVar", then you are all set.
For a Simulink model parameter, it always looks for it first in the "Model Workspae" and then the "base workspace".
  2 件のコメント
Dimuthu Arachchige
Dimuthu Arachchige 2022 年 6 月 6 日
編集済み: Dimuthu Arachchige 2022 年 6 月 6 日
Can we define a structure variable as a parameter? Because I am trying to read the stereoParameters for image rectification and it is not a scalar. I tried to define the structure varible as you suggested, but got an error.
Model Error:
Expression 'stereoParams' for initial value of data 'stereoParams' must evaluate to logical or supported numeric type.

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

カテゴリ

Help Center および File ExchangeInteractive Model Editing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by