Hi Jerry,
In type editor it throws an error if the common variable used to define the dimennsion is not available in the global scope, however there is an alternative.
I'm not sure if this is what you are looking for, but here is my approach:
The model consists of two buses with two array elements each and in bus1 each bus element array has dimension 2 and in bus bus2 each bus element array has dimension 3.
I have created a data dictionary 'myDictionary.sldd', which contains:
- Two matlab variables dim1 and dim2, which hold the dimension of array element of bus1 and bus2.
- Two bus objects, mybus1 and mybus2 are created where, two bus element arrays are created 'a' and 'a1' for bus1 and 'b' and 'b1' for bus2.
In the data dictionary: bus object --> design tab --> Bus elements-->Dimensions field, specify dimensions as 'dim1' for both elements of bus1 and 'dim2' for bus2.
Programatically(base workspace):
elem(1)=Simulink.BusElement;
elem(2)=Simulink.BusElement;
mybus3.Elements(1).Dimensions='dim3';
mybus3.Elements(2).Dimensions='dim3';
for data dictionary:
elem(1)=Simulink.BusElement;
elem(2)=Simulink.BusElement;
myDictionaryObj = Simulink.data.dictionary.open('myDictionary.sldd');
dDataSectObj = getSection(myDictionaryObj,'Design Data');
new_entry=addEntry(dDataSectObj,'mybus4',mybus4);
new_dim_var=addEntry(dDataSectObj,'mydim',5);
busobject_details = getEntry(dDataSectObj,'mybus4');
bus_objval=getValue(busobject_details);
bus_objval.Elements(1).Dimensions=new_dim_var.Name;
bus_objval.Elements(2).Dimensions=new_dim_var.Name;
setValue(busobject_details,bus_objval)
This is how it looks in the model: