Sub-libraries do not appear in the library browser
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponse acceptée
Fangjun Jiang
le 16 Août 2011
Modifié(e) : John Kelly
le 27 Fév 2015
You need to add a file slblocks.m to "register" your customized library.
3 commentaires
Fangjun Jiang
le 17 Août 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
le 17 Août 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).
Plus de réponses (2)
Phil Taylor
le 15 Nov 2012
Modifié(e) : Phil Taylor
le 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.
0 commentaires
Voir également
Catégories
En savoir plus sur Creating Custom Components and Libraries dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!