필터 지우기
필터 지우기

Can't use structs as outputs from simulink models

조회 수: 14 (최근 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 CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by