Create bus of type 1*2 struct

2 次查看(过去 30 天)
HARI
HARI 2022-2-9
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 中查找有关 Sources 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by