Create bus of type 1*2 struct
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
0 Kommentare
Antworten (1)
Benjamin Thompson
am 10 Feb. 2022
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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Sources finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!