Guy on Simulink

Simulink & Model-Based Design

A Historical Tour of the Library Browser 20

Posted by Seth Popinchalk,

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. 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.

20 CommentsOldest to Newest

Volkmar replied on : 3 of 20

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?

Jeremy replied on : 4 of 20

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

Devdatt Lad replied on : 5 of 20

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.

Graham replied on : 6 of 20

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

Seth replied on : 7 of 20

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

Kevin replied on : 8 of 20

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

Rajkiran replied on : 9 of 20

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

Seth replied on : 10 of 20

@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!

sakthivel replied on : 11 of 20

Hi,

I have created a module using Xilink black box with VHDL. I added to simulink library using slblocks.m file. but when i am trying to use my lib it showing error. VHDL file not found. I kept all VHDL files in library folder only. any suggestion plz?

thanks in advance

Seth replied on : 12 of 20

@sakthivel – I am not familiar with the Xilinx black box. Some 3rd party blocks use a CopyFcn to add information to the model or modify the block when it is added to a new model. When these blocks are added to the model, they might delete this function so it doesn’t repeat that step. If your block doesn’t have this callback, it may fail in strange ways. Your best bet might be to contact the maker of the block. Good luck.

PRao replied on : 13 of 20

I created a test library as described above with two blocks (both simple subsystems with one input and one output). It shows up in the “Libraries” pane of the library browser. But nothing shows up in the pane on the right. The Block Description window in the bottom says “No block is selected”. I am creating a library for the first time so I am sure I have missed something. Any help would be appreciated. Thanks.

Seth replied on : 15 of 20

@PRao – It is hard to know what is working/not working for you. Subsystems can be used as sub-libraries, so you may want to add some non-virtual blocks (like a Gain) to your library, then test it again. Good luck!

Josip replied on : 16 of 20

Hi,

I created a custom library in Simulink 2008a on Windows. It contains few sublibraries and one block. Library appears in the Library Browser but when I select it, only the one block is displayed on the right side of the Browser. Sublibraries are not visible. When I open the library by right clicking on it in the tree view and selecting ‘Open MyLibName library’, I can normally browse through sublibraries. Any clues?

Thanks in advance!

RandomPerson replied on : 17 of 20

Hi,

I’m not sure if you will reply to a comment on a blog post written 4 years ago but here goes:

I managed to implement my own Simulink library following the instructions posted here, everything seems to work but there are a few things that I havent found a solution for:

I want to implement a library block which depends on several level-2 s-functions written in m code. The m code are written in terms of different function files – the Simulink block relies on them to access functions not normally accessible within Simulink. The library block fails to function if the .m code for the s-function is not in the same directory, claiming that the file is not found. If i do include these .m files in the same directory, everything is fine, however, i want to avoid having to include these .m files in every instance that this library is used. Even when specifying a full directory path (ie: C:\Program Files\MATLAB\R2008a\toolbox\\.m) in the M-S-function m-file name entry, it fails to find it. I’ve ensured that all the s-function m code is within the same directory path as the library model file. When running the ‘path’ command, the directory corresponding to my custom library is visible, so ideally it should be able to access my custom s-functions contained inside them as well.

I was looking at some examples of how the standard Simulink libraries are implemented, many of them use level 1 s-functions to interact with .mex files, located deep within the sub-directories of the /toolbox/ folder. In the slblock.m file for each library, there is no mention of the directory paths for these dependent mex files. Is there some command i should be aware of that updates Simulink’s Library’s access to .mex/s-function code that i should be aware of?

Thanks,

Michael replied on : 19 of 20

Hi Seth
I have a problem to use user defined library block: I can use the blocks in library, but I can’t see its help file. When clicking help button, I get the error “Warning – Documentation File Not Found”. But other people don’t have this problem when they use the same library block. What is wrong with my simulink setting?

Thanks
Michael

Add A Comment

What is 7 + 10?

Preview: hide