Clear Filters
Clear Filters

How do I create a structure in Simulink without MATLAB Function block?

3 views (last 30 days)
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.

Accepted Answer

Jason Firth
Jason Firth on 11 Jun 2019
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"

More Answers (0)

Categories

Find more on Event Functions in Help Center and File Exchange

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!