Can't use structs as outputs from simulink models

12 ビュー (過去 30 日間)
guy lasri
guy lasri 2019 年 7 月 1 日
回答済み: Githin George 2024 年 2 月 9 日
Hello,
After a few tries and reading in matlab forums i found out that it is not possible to use struct as output, and the other options is to insert struct in to bus.
While there is a lot of mentiones about it, there is not good example on how to do it.
I am using matlab function model which is under user-defined library, and use the following function:
function simconf = fcn
Interetions = 2;
simconf.Interetions = Interetions;
end
I get this error: "Derived output was of type struct. 'Inherited type' is unsupported for this type and a defined bus object must be used instead. Click on 'simconf' and set data type for 'simconf' to be 'Bus: <object name>', where '<object name>' is the name of a bus object from the MATLAB workspace."
  1 件のコメント
VIGNESH BALAJI
VIGNESH BALAJI 2024 年 1 月 31 日
I also get this type of error. Did you find an answer ?

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

回答 (1 件)

Githin George
Githin George 2024 年 2 月 9 日
Hello,
The error message that you have provided indicates that “struct” objects cannot be the output of a “MATLAB function” block in Simulink. You can change the output type of the function block to a “Simulink.Bus” object to correct this issue. For this task you will have to define your “Simulink.Bus” object either in base workspace or in the interactive “typeeditor”. The following code creates a “Bus” object in the workspace with the property ‘Interetions’
elems(1) = Simulink.BusElement;
elems(1).Name = 'Interetions';
TopBus = Simulink.Bus;
TopBus.Elements = elems;
Once you have created the Bus object, open the model explorer, and navigate to the “MATLAB function” block listed under your model. In the datatype section labelled “Type”, you can update the value with “Bus: TopBus” to assign the datatype correctly. Now you can use the “Bus” object without issues in the “MATLAB function” block. You can have a look at the attached screenshot for better clarity on the workflow.
The following documentation links may prove helpful in better understanding these concepts.
I hope this helps.

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by