Clear Filters
Clear Filters

How to save Bus Object with all dependent Bus Objects to a file programmatically?

24 views (last 30 days)
I have a script that creates several bus objects in the workspace. There is one main bus object with many bus objects nested inside the main one with several layers. I need to save them all to a file. The problem is, the script won't know the names of the bus objects other than the top level one. So I need to somehow save the top level bus object with all its dependent bus objects. I can do this via the bus editor very easily. You just right click on the bus object and choose "Export of bus object with Dependent Bus Objects to File". That's exactly the functionality I want, but I need to be able to do it programmaticaly. Is this possible?

Answers (1)

Nathan
Nathan on 24 Oct 2017
Edited: Nathan on 24 Oct 2017
You can create a Cell array from the top level Simulink Bus and then save that cell array:
topLevelCellArray = topLevelBusName.objectToCell; save('filename.mat','topLevelCellArray);
And then when you load the cell array into the the base workspace again convert it to Simulink bus objects: load('filename.mat'); Simulink.Bus.cellToObject(topLevelCellArray)

Categories

Find more on Component-Based Modeling in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!