- 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.
Evaluating Parameters in Simulink Data Dictionary Bus Objects
23 views (last 30 days)
Show older comments
I'm setting up a Simulink data dictionary that contains parameters and bus objects. Some elements in the bus objects are arrays that have a common dimension. I want to use a single parameter in the data dictionary to centrally specify the dimension of multiple bus object array elements.
The bus object editor does not seem to evaluate the parameter value when I enter the parameter name in the 'Dimensions' field of the bus object element. I get an error box that says "Undefined function or variable." I’ve also tried to add the parameter to the Workspace, but it was not evaluated either.
It seems that I can only specify a literal value for a bus object element dimension if it is created in a data dictionary.
How can I reference a parameter or a MATLAB variable that is stored in the same data dictionary?
0 Comments
Answers (1)
Nagendra
on 11 Apr 2024
Edited: Nagendra
on 11 Apr 2024
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:
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):
%% Create bus using type editor or command line API, by setting the element dimension to default value
% define elements
elem(1)=Simulink.BusElement;
elem(1).Name='c';
elem(2)=Simulink.BusElement;
elem(2).Name='c1';
% Create a bus
mybus3 = Simulink.Bus;
mybus3.Elements=elem;
dim3=4; % common dimension variable
mybus3.Elements(1).Dimensions='dim3'; % here the 'dim3'(dimension variable) and...
mybus3.Elements(2).Dimensions='dim3'; % mybus3 (bus object) are already
% in base workspace.
for data dictionary:
%% Create bus using type editor or command line API, by setting the element dimension to default value
% define elements
elem(1)=Simulink.BusElement;
elem(1).Name='d';
elem(2)=Simulink.BusElement;
elem(2).Name='d1';
% Create a bus
mybus4 = Simulink.Bus;
mybus4.Elements=elem;
%% Create data dictionary
% Simulink.data.dictionary.create('myDictionary.sldd'); % if the dictionary is not existing, create a new one
%% Open the data dictionary (ssuming a data dictionary is already created) and move the newly created bus object to the data dictionray
myDictionaryObj = Simulink.data.dictionary.open('myDictionary.sldd'); % open the data dictionary
dDataSectObj = getSection(myDictionaryObj,'Design Data'); % access the Design Data section
new_entry=addEntry(dDataSectObj,'mybus4',mybus4); % Add the newly created bus objet to data dictionary
new_dim_var=addEntry(dDataSectObj,'mydim',5); % create common dimension variable for the bus element array
clear mybus4 % remove the created bus object from base workspace after adding it to the data dictionary
%% Get the bus object details and assign the dimension variable to Dimensions filed
busobject_details = getEntry(dDataSectObj,'mybus4'); % get bus object details
bus_objval=getValue(busobject_details); % get the values of bus object
bus_objval.Elements(1).Dimensions=new_dim_var.Name; % get the dimension of bus element 1, for subsequent elements append the number in paranthesis
bus_objval.Elements(2).Dimensions=new_dim_var.Name;% this assigns the dimension variable created in dictionary to Dimensions field
setValue(busobject_details,bus_objval)% assign the modified bus property to the bus object in data dictionary
This is how it looks in the model:
0 Comments
See Also
Categories
Find more on Manage Design Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!