How to use Simulink.B​us.createM​ATLABStruc​t function with Simulink Data Dictionaries

17 ビュー (過去 30 日間)
simon pierce
simon pierce 2018 年 6 月 11 日
回答済み: Sebastian 2023 年 10 月 10 日
I have a Simulink Constant Block where the value is
Simulink.Bus.createMATLABStruct('myBus');
in order to create a Simple test-harness.
If the bus-object for 'myBus' is in the base-workspace then it works. However, if the bus-object is defined (solely) in a linked data-dictionary then it does not.

回答 (4 件)

Ivan
Ivan 2019 年 1 月 23 日
編集済み: Ivan 2020 年 1 月 17 日
you can also try next code:
dd_name=get_param('Model Name','DataDictionary');
scope = Simulink.data.DataDictionary(dd_name);
pStruct=[];
dims=[1,1];
obj='BUS_NAME';
BUS_NAME_MATLABStruct = Simulink.Bus.createMATLABStruct(obj, pStruct, dims, scope);

simon pierce
simon pierce 2018 年 7 月 2 日
I have created the following function as a stopgap.
function myStruct = CreateMatlabStructDD( busName , partialValues )
% this function relies on the bus-object being specified in the simulink
% data dictionary
% get this models data dictionary
dataDictionaryFile = get_param(gcs, 'DataDictionary');
% create a data dictionary object
slddObject = Simulink.data.dictionary.open(dataDictionaryFile);
% get the design data section
section = getSection(slddObject, 'Design Data');
% get the buses
entries = find(section, '-value', '-class', 'Simulink.Bus');
% find the one we want
myBus = find(entries, 'Name', busName);
% turn in ot a cell array
myBusCell = getValue(myBus);
% assign in to the base workspace, with the same name as in the
% data-dictionary
assignin('base', busName, myBusCell);
% create the structure with Mathworks createMATLABStruct function, which is
% possible now that it is in the base workspace
myStruct = Simulink.Bus.createMATLABStruct( busName, partialValues );
end

Robert Simpson
Robert Simpson 2018 年 6 月 11 日
I also have this issue. Automatically created test harnesses try to set initial condition of ZOH blocks by running Simulink.Bus.createMATLABStruct('.....'); in the mask of the signal spec block. But this fails.

Sebastian
Sebastian 2023 年 10 月 10 日
If you have nested buses in your data dictionary it gets even more complicated, because you have to load all referenced buses to the base workspace as well.
Is there an easier way available in the latest releases?

カテゴリ

Help Center および File ExchangeModeling についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by