User defined Simulink blocks, Hierachical design, Code Re-use...

1 view (last 30 days)
I must be missing something fundamental - I can't believe this is as complex to do in Simulink as it appears...
Let me start by saying I am a wildly avid fan of Matlab - I've written the most splendid, stable, complex and huge Matlab code over the last 20 years, literally hundreds of thousands of lines with GUI's and the works. Big, Big fan.
I've recently engaged with Simulink, and I can't believe the process of creating and re-using a user defined chunk of code is so byzantine!
Scenario: I'm simulating a mechanical system, so I need masses, springs, dampers, some hysteresis functions, you know, the ususal. And I want my blocks to track their motion states - simple, I'll make up some custom blocks.
In a "facign" data flow/block diagram product, Labview, this is like falling off a log. Design the function, wire input and output terminals to an icon, save the VI, then add your custom VI's to the block browser so you can just pick and drop your custom VI repeatedly into your higher level model(s).
Assuming I could do exactly the same thing in Simulink, my searches led me to such as this: http://www.mathworks.com/help/simulink/ug/creating-block-libraries.html
And exclamations like WTF!
Please, someone, point me to a tutorial that explains the simple way to do this, my faith in Mathworks is being shaken!
Thanks,
Alex.

Answers (1)

Ryan G
Ryan G on 15 Jul 2013
Hi Alex,
Based on the description I believe you want a library. Although that link has a lot of information, they are really quite easy on a basic level. It's important to remember that there is a lot of information because, as you build up models, they can become quite complex with a lot of users/contributors.
Based on your description there are a number of different things you can do. Depending on the complexity of the components, you may even want model references (let's not go there yet)
This blog post and this video should be more user friendly description of libraries.
This is my workflow for doing the process:
1) Make your component in Simulink
2) Highlight everything you want to re-use, right-click, create subsystem
2a) (optional) mask the subsystem and define parameters
3) File -> New -> Library
4) Copy the block into the library and save it. You can add multiple subsystems/components to your library. You can add this library to the browser as well.
5) (This part could admittedly use some improvement) Delete the subsystem in the model and replace it with the block in the library. This creates a library link. When you change the subsystem in the library, the changes will automatically propagate. You can disable the link in the model and then propagate the changes back to the library.
You could do this all in the library, but you should make sure the component works before adding it to a library.
Hope this helps you get started. If you run into any roadblocks or think this doesn't work well, I'd like to hear your feedback.

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!