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

3 次查看(过去 30 天)
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.

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Event Functions 的更多信息

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by