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

24 views (last 30 days)
simon pierce
simon pierce on 11 Jun 2018
Edited: Ivan on 17 Jan 2020
I have a Simulink Constant Block where the value is
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.

Answers (3)

Ivan on 23 Jan 2019
Edited: Ivan on 17 Jan 2020
you can also try next code:
dd_name=get_param('Model Name','DataDictionary');
scope =;
BUS_NAME_MATLABStruct = Simulink.Bus.createMATLABStruct(obj, pStruct, dims, scope);

Robert Simpson
Robert Simpson on 11 Jun 2018
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.

simon pierce
simon pierce on 2 Jul 2018
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 =;
% 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 );




Community Treasure Hunt

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

Start Hunting!