Create bus of type 1*2 struct

조회 수: 2 (최근 30일)
HARI
HARI 2022년 2월 9일
답변: Benjamin Thompson 2022년 2월 10일
Hello,
I need to create a bus of type 1x2 struct(with 5 fields).Please see the attached picture.fields contain scalar,vector and matrix datatypes.
when i use "Simulink.Bus.createObject(bus_struct)" it results in 1*1 struct.
can someone give a hint in this regard?
Thanks!

답변 (1개)

Benjamin Thompson
Benjamin Thompson 2022년 2월 10일
Simulink.Bus.createObject is mainly intended to create bus definitions to work with in the bus editor. Once you see your bus definition in the bus editor, you can right click on your bus definition and select Create/Edit a Simulink Parameter object. Then it generates sample M code in the MATLAB editor, for example the below:
%% ------------------------------------------------------------------
% You can modify the values of the fields in NestedBus_MATLABStruct
% and evaluate this cell to create/update NestedBus_Param
% in the MATLAB base workspace.
% -------------------------------------------------------------------
NestedBus_MATLABStruct = struct;
NestedBus_MATLABStruct.Chirp = 0;
NestedBus_MATLABStruct.Sine = 0;
NestedBus_Param = Simulink.Parameter;
NestedBus_Param.Value = NestedBus_MATLABStruct;
NestedBus_Param.Complexity = 'real';
NestedBus_Param.CoderInfo.StorageClass = 'Auto';
NestedBus_Param.Description = '';
NestedBus_Param.DataType = 'Bus: NestedBus';
NestedBus_Param.Min = [];
NestedBus_Param.Max = [];
NestedBus_Param.DocUnits = '';
clear NestedBus_MATLABStruct;
Then, instead of assigning a single 1x1 struct to the Value field of the parameter object, you assign a bus array that you can construct one one struct like this:
>> BusArray(1) = NestedBus;
>> BusArray(2) = NestedBus;
>> BusArray
BusArray =
1×2 Bus array with properties:
Alignment
PreserveElementDimensions
Elements
Description
DataScope
HeaderFile
NestedBus_Param.Value = BusArray;
There are probably many ways to do this, hopefully it is a start. Or, in Simulink if you have a single 1x1 struct in a Parameter object you can use the Vector concatenate block to duplicate it into a bus array. Or create more than one 1x1 struct Parameter objects if you wanted them to have different values and concatenate them with Vector concatenate.

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by