Guy on Simulink

Simulink & Model-Based Design

Tips for dealing with Libraries

Today I will share a simple trick that might save you some time if you are dealing with large Simulink models componentized using libraries.

Long Time to Save

Earlier this week, I received a large model made of multiple subsystems stored in a library file. I had to do some modifications to the library. When I was done with my modifications, I clicked on the Save button, it took significantly longer than I expected, more than a minute.

Curious, I decided to profile the saving operation to try understanding what was happening:

Starting the MATLAB Profiler

Here are the results:

Profiler results

The Explanation

When I saw that most of the time was spent in a function called "generateSVG", I knew exactly what was happening.

As described in the documentation page Add Libraries to the Library Browser, if you want your library file to appear in the Simulink Library Browser, you need to enable the EnableLBRepository property of the library.

Enabling Library Browser Repository

When this option is enabled, Simulink will save an image file for each block to be displayed in the Library Browser. This image is in scalable vector graphics format (SVG). You do not see those image files, but they are inside the SLX library file. As far as I understand, this is done to speed up the opening of the Library Browser.

Sure enough, disabling this option made the time to save the library pass from over a minute to just a few seconds.

Disabled Library Browser Repository


Based on that, I recommend turning this flag on or off depending on your workflow. When you are in editing mode and you modify and save the library often, disable EnableLBRepository. When your library is ready to be released and deployed to other users who will access it from the Library Browser, enable EnableLBRepository.

A few more tips...

While we are talking about speeding up workflows, here is another trick I like. In my startup.m, I like to add the following two lines:

Speeding load

By default, Simulink and the Library Browser are loaded in memory only the first time you simulate or open a model. Since I always use Simulink, I prefer having the loading done as soon as MATLAB launches.

Now it's your turn

Do you have other tips or tricks like those? Share them with us by leaving a comment below.

  • print


To leave a comment, please click here to sign in to your MathWorks Account or create a new one.