Nested buses in base workspace

조회 수: 7 (최근 30일)
Oliver McEnteggart
Oliver McEnteggart 2012년 7월 23일
I'm trying to define a nested bus structure in the base workspace of MatLab. However, I'm not sure how I should actually write the code for it. Here is my attempt.
% names={'Ep_struct_Ex000_struct'}; %Define names of signals in this bus element
clear elems;
clear numElems;
for i=1
elems(i) = Simulink.StructElement;
elems(i).Name = char(names(i));
elems(i).Dimensions = 1;
elems(i).DataType = 'double';
elems(i).SampleTime = -1;
elems(i).Complexity = 'real';
elems(i).SamplingMode = 'Sample based';
names1={'Ex000_enum'...
,'E1000_DEF'...
,'E3000_DEF'...
,'E10k30A_DEF'...
,'E10k40A_DEF'...
,'E10k50A_DEF'...
,'E10kRot135degFS_DEF'...
,'E10kRot16turnFS_DEF'}; %Define names of signals in this bus element
clear elems1;
clear numElems1;
numElems1 = length(names1)
for i=1:numElems1
elems1(i) = Simulink.BusElement;
elems1(i).Name = char(names1(i));
elems1(i).Dimensions = 1;
elems1(i).DataType = 'double';
elems1(i).SampleTime = -1;
elems1(i).Complexity = 'real';
elems1(i).SamplingMode = 'Sample based';
end
elems(1)=Simulink.StructElement;
elems(1).Elements=elems1;
end
Ep_struct=Simulink.Bus; %Define bus
Ep_struct.Elements=elems; %Define whats in this bus
This code is meant to produce a Bus, Ep_struct which contains one elementEp_struct_Ex000_struct which itself is a bus which contains the elements, Ex000_enum...................E10kTor16turnFS_DEF.
The real structure I am trying to code is a lot more complicated than this but if I work out how to program 1 nested bus I should be able to do as many as I need.
So what is wrong with my code?

답변 (1개)

Kaustubha Govind
Kaustubha Govind 2012년 8월 10일
편집: Kaustubha Govind 2012년 8월 10일
I think you just need to make the DataType field of the element that is another bus equal to something like 'Bus: elementEp_struct_Ex000_struct'. For example, a simpler version:
bus1 = Simulink.Bus;
el11 = Simulink.BusElement;
el11.Name = 'myel11';
el12 = Simulink.BusElement;
el12.Name = 'myel12';
bus1.Elements = [el11 el12];
bus2 = Simulink.Bus;
el21 = Simulink.BusElement;
el21.Name = 'myel21';
el21.DataType = 'Bus: bus1';
el22 = Simulink.BusElement;
el22.Name = 'myel22';
bus2.Elements = [el21 el22];
The resultant structure should be:
struct bus1 {
double myel11;
double myel12;
};
struct bus2 {
bus1 myel21;
double myel22;
};

카테고리

Help CenterFile Exchange에서 Composite Interfaces에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by