MATLAB: How to create a structure in Simulink without MATLAB Function block

simulinkstructures

Hi All,
I am trying to implement a C-like structure in Simulink.
I found the instruction how to do it with MATLAB Function block :
Unfortunately I am not allowed to use MATLAB functions in my Simulink model. That is shy I have a question.
Do You know any other way to create a C-like structure in Simulink without MATLAB function block or MATLAB system block?
I will be very thankful for any information.

Best Answer

You need to create a bus object. You can do this by calling
myStruct = struct('field1',0,'field2',0);
busInfo = Simulink.Bus.createObject(myStruct);
MyDataStructureType = eval(busInfo.busName);
clear(busInfo.busName)
Then you can export the bus definition to a file by running
Simulink.Bus.save('MyBusDefinitions.m','object',{'MyDataStructureType'})
Then in your simulink model, you can use a bus creator block with the output data type set to "Bus: MyDataStructureType". Or you can create a subsystem with one outport connected to a ground and set the output data type of the output port to "Bus: MyDataStructureType". Then you can use the Bus Assignment block to assign elements to the bus. If you have an existing c-header file that you would like to use as the structure definition in the generated code, you can set the MyDataStructureType.HeaderFile = ''; to your specific header file in the "MyBusDefinitions.m"