Sub-libraries do not appear in the library browser

22 views (last 30 days)
I'm finding that using the instructions from Simulink>User's Guide>Managing Blocks>Working with Block Libraries>Creating Block Libraries to create sub-libraries, these sub-libraries are not shown in the library browser. Is this to be expected and do I need to customise the library browser to have them displayed?

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 16 Aug 2011
Edited: John Kelly on 27 Feb 2015
You need to add a file slblocks.m to "register" your customized library.
  3 Comments
Fangjun Jiang
Fangjun Jiang on 17 Aug 2011
I don't fully understand what you mean by main library and sub-library. It sounds like that you are composing your library through multiple files. Maybe the main library file contains a reference to the sub-library files. I don't think Simulink library is constructed that way. Each library has only one file. The hierarchy structure you see in the library browser is just the model/subsystem hierarchy. Right click the Simulink library, choose "Open the Simuink library", you will see a model open, double click any of the block, for example, "source", you will see another model window. But that is still the same model file. "source" is just a subsystem block in the root model. Is this different than your model/library structure?
Kaustubha Govind
Kaustubha Govind on 17 Aug 2011
I've not done this before, but I tried looking at some examples from the product. For example, if you find one or more of the Toolbox libraries show up with sub-libraries in the Simulink library browser, it's worth looking into how slblocks.m is defined for them. You can locate all slblocks.m in your installation by using "which -all slblocks". I looked at the library for the Computer Vision Toolbox for example, and it looks like the sub-libraries are never identified in the slblocks.m file. They are simply masked empty subsystems that have OpenFcn set to the sub-library name (this is like just saying 'libraryname" at the MATLAB command prompt which would open up the library model if it is on path).

Sign in to comment.

More Answers (2)

Phil Taylor
Phil Taylor on 15 Nov 2012
Edited: Phil Taylor on 15 Nov 2012
Tested on R2012a
I've also been struggling to get separate library files to appear as children of another library. Firstly, I followed the documentation, but that only shows how to add multiple top-level libraries. In the end I found the solution in the Simscape libraries' slblocks.m files.
A number of things to note:
  • Every library must have an slblocks.m file. Don't change the name of it either.
  • For children libraries you will need to create a folder to hold the mdl file and the slblocks.m file. The library can have any (unique) name you want. The folder must be added to the path.
  • Every slblocks.m file on the path is automatically read by the Library Browser when you refresh it (F5). So you never need to run these files explicitly to test them.
  • Every child library will have to be linked into the parent library using the subsystem OpenFcn technique described in the documentation. Because they are uniquely named and on the path you don't need any relative path, just use open_system('name_of_library');
The following example assumes 2 child libraries in one top-level library.
The solution for both children is the same. Setup the Browser struct in each slblocks.m as follows:
Browser(1).Library = 'child_n_library_mdl_name'; % n = 1, 2, etc.
Browser(1).Name = 'Text name of child_n'; % n = 1, 2, etc.
Browser(1).PanelIcon = 'some_image.jpg';
Browser(1).IsTopLevel = 0;
blkStruct.Browser = Browser;
The solution for the top level library is to setup the Browser struct in slblocks.m as follows:
Browser(1).Library = 'top_level_library_mdl_name';
Browser(1).Name = 'Text name of top level';
Browser(1).Type = 'Palette';
Browser(1).Children = { 'Text name of child_1', ...
'Text name of child_2', }; % and so on
blkStruct.Browser = Browser;
(Note, always use Browser(1), don't think you need to put Browser(2) for the second child; remember that each slblocks.m represents its own library object according to the Library Browser.)
After doing this for all your top-level and children libraries you should have them appear in the Library Browser (with icons if you've included them) in a true hierarchical fashion. You can also mix true subsystems and separate library subsystems in the same top-level library. I assume you could extend this functionality to lower-level sublibraries by adding a Children field to any of your Children libraries' Browser structs, but I haven't tried that myself.

Nigel
Nigel on 17 Aug 2011
Firstly to Fangjun Jiang, the help reference I gave does describe the ability for a library to reference other library files which was the mechanism I was trying to implement.
Secondly to Kaustubha Govind, your suggestions have been helpful, I hadn't realised that the OpenFcn would just take the sublibrary name unquoted.
Thank you for both your responses.

Categories

Find more on Creating Custom Components and Libraries in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!