Seth on Simulink

March 18th, 2008

A Historical Tour of the Library Browser

When I started using Simulink, the libraries were organized a little differently than they are today. There were fewer blocks and no such thing as a Library Browser. Take a look at Simulink 1.3c from 1996.

The Simulink 1.3c Library

This version was a little before my time. However, users of that era may remember it. When I joined The MathWorks in 1998, the Simulink 2 library looked like this.

The Simulink 2 Library

The main challenge with Simulink 2 was screen real estate. In order to build a model, you had to open each of the sub-libraries in a new window. First, you would need a Signal Generator, so you open Sources. Next you need a Unit Delay, so you open the Discrete library. Then you need a Scope, so you open Sinks, yet another window. In a short time your desktop would look like this.

Simulink 2 Libraries on the desktop

In the latter part of 1998 Simulink 3 was introduced. Along with it came the Library Browser on the PC. It was revolutionary because you didn't have to clutter your entire desktop with windows to get access to the blocks you needed. This made a real difference if all you had was an 800x600 pixel monitor.

Simulink 3 Library Browser

Unfortunately users on non-Windows platforms were stuck with the old interface. Even Simulink developers who preferred Linux we relegated to the "old school" libraries. Luckily, screen sizes have continued to increase since the 90s.

R2008a

With the release of R2008a all platforms can now use the same Library Browser. Our Linux-loving Simulink developers can now use the same great Library Browser we have on the PC. The Library Browser has a new grid view in addition to the traditional list view.

Simulink R2008a all-platform Library Browser

Notice the search tab, item 1 in the diagram below. This is an improvement over the old version. When searching, you will now see all the results in one place rather than having to walk through the tree to view each match. The results are grouped by library and can be collapsed to simplify browsing (2). The search options (3) also allow for regular expressions.

Simulink R2008a Library Browser Search Feature

The R2008a Library Browser has improved graphics and better performance compared with previous releases. The old version would redraw all blocks each time you viewed them, and in order to see the blocks in a library it had to be loaded into memory. The new browser uses caching to improve performance. The cache also enables faster searches without fully loading all libraries into memory. By the way, building the cache incurs a one time cost which you may notice the first time you start the Library Browser.

After seeing the new Library Browser, most people ask the same question:

But Seth, how do I add my library to the browser?

It has always been possible to add a library to Simulink, and you can read about it in the documentation. In order to add a library to the browser, create an slblocks.m file. You should store it in the directory with your library. I’m going to use the example library from a previous post. The most basic slblocks.m file looks like this:

function blkStruct = slblocks  
%SLBLOCKS Defines a block library.  
 
% Library's name. The name appears in the Library Browser's  
% contents pane.  
 
blkStruct.Name = ['A PID' sprintf('\n') 'Library'];  
 
% The function that will be called when the user double-clicks on
% the library's name. 
 
blkStruct.OpenFcn = 'pidLibrary';  
 
% The argument to be set as the Mask Display for the subsystem. You
% may comment this line out if no specific mask is desired.  
% Example: blkStruct.MaskDisplay = 'plot([0:2*pi],sin([0:2*pi]));';
 
blkStruct.MaskDisplay = '';
% End of blocks

After creating the library, you will need to select Refresh Tree View from the Library Browser View menu.

Simulink R2008a Custom Library

It is also possible to specify multiple libraries within the same slblocks.m. I recommend looking at the other slblocks.m files on your path for examples.

>> which -all slblocks

A well-documented example is in $matlab/toolbox/simulink/blocks/slblocks.m. You can start by making a copy of that one and then edit it to reference your library.

Try it yourself

If you have never added a library, try making a library of your most commonly used components. Select File -> New -> Library from the Library Browser. Drag in your favorite blocks and add this to the Library Browser to increase your productivity.

Do you have custom libraries? Are they displayed in the Library Browser? Let me know in the comments.

10 Responses to “A Historical Tour of the Library Browser”

  1. Andy replied on :

    Did it really take 10 years to get the library browser on unix? Wow!

  2. Simon Greenwold replied on :

    It didn’t! It took one year. It took nine years before it got scheduled.

  3. Volkmar replied on :

    Will it take another 9 years to release a documented and supported uitree/uitreenode widget that can be used to build tree browsers for other applications without the risk of using an unsupported feature?

  4. Jeremy replied on :

    Hi Seth,

    I have been looking at SimEvents modelling with the Image processing blocksets. I want to record the output video of the “Video Streaming Over Bandwidth-Limited Communication Channel” demo, however I cannot write the data directly from the video viewer to a multimedia file as I get a invalid sample time error. I run out of memory if I try to write to workspace with a large number of frames. Is there a better way of doing it?

    Thanks Jeremy

  5. Devdatt Lad replied on :

    Hi Jeremy,

    Insert Rate Transition Blocks in each of the R,G,B color lines before feeding them to the To Multimedia File block. In each of those rate transition blocks set the output sample time to 1/30 (which is the rate of the input video). This should work.

    Devdatt

    PS: Please post off-topic questions to the MATLAB community newsgroup comp.soft-sys.matlab. Feel free to continue this thread on the newsgroup.

  6. Graham replied on :

    Hi Seth,

    I’m using a custom library in Simulink 2008a on Windows. It has some hierarchy, so it contains some sub-libraries with different numbers of blocks in them.

    I find that switching between sub-libraries is slow, particularly for those with a lot of blocks. One contains 40 blocks and takes 10-12 seconds to load, and this doesn’t improve once it has already been loaded. I’m not talking about opening the library browser, I’m talking about moving back and forth between sub-libraries.

    The same library in 2007b switches between sub-libraries very quickly - there is hardly any noticeable delay.

    Is there anything I can do to improve this?

    Regards,
    Graham

  7. Seth replied on :

    @Graham - That is not something I have encountered before. Please work with technical support to investigate this problem further.

  8. Kevin replied on :

    Hi Seth,

    Thank you for much for the great tutorial.
    I am using MATLAB R2007a, and I have successfully added my own library to the Simulink Library Browser although there is a small problem, which I have to run the M-file stored in my library folder. Thank you so much

    Regards,

    Kevin

  9. Rajkiran replied on :

    thank u for the tutorial. Well i tried adding the library. however it didn’t work. i tried adding the path and restarting matlab, still it didn’t work.

    Regards
    Rajkiran

  10. Seth replied on :

    @Rajkiran - I don’t know what to suggest. Check that you named your file “slblocks.m”, that is is on the path, (which -all slblocks.m) and that it returns a valid blkStruct structure. Good luck!

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Seth Popinchalk is an Application Engineer for The MathWorks. He writes here about Simulink and other MathWorks tools used in Model-Based Design.
  • wei: @Ashish, I agree with your observation on compiler optimization but fail to see why Han’s code would be...
  • Ashish Sadanandan: Han, Sorry for butting in with a reply, but the modification to the for-loop you’ve...
  • arun kumar: dear seth i have been involved in developing and simulating asynchronous systems for my VLSI lab. in...
  • Han Geerligs: Hi Aarti, thanks for providing the example! I was just wondering why the lines model_YDim = model_XDim;...
  • Seth: @Han - Aarti’s response is in a post titled Generated Code for Variable Size Signals.
  • garla: what is advantage of exporting the bus object with the format as “cell” and “object” ....
  • J.r: @ Guy - Example sent to your account. Thank you.
  • Guy: @ J.r - The ability for atomic subsystems and Model Reference to remove the “fake algebraic loop”...
  • J.r: Sorry to hit an old thread, but this seems like the best place to solicit help on this topic. Is there supposed...
  • Bindu: please tell me how can i get the sampling time used in simulation

These postings are the author's and don't necessarily represent the opinions of The MathWorks.