Main Content

Add Libraries to the Library Browser

This example shows how to create a block library and add it to the Simulink®自由rary Browser. This example also shows how to add a sublibrary.

To specify information about your library, you create a function namedslblocks.

Add Library to the Library Browser

  1. From the Simulink start page, select空白的图书馆and clickCreate Library.

    Note

    The Library Browser only supports libraries. You cannot display the contents of a model in the Library Browser.

  2. Add aGainblock to the library.

  3. In the MATLAB®Command Window, enter this command to set theEnableLBRepositorylibrary property to'on'. Your library will appear in the Library Browser only if this property is on when you save your library.

    set_param(gcs,'EnableLBRepository','on');
  4. Save the library in a folder on the MATLAB path. For this example, name the librarymylib.

  5. In the MATLAB Current Folder Browser, open the folder that containsmylib, then clickNew Scriptin the MATLAB Toolstrip.

  6. In the MATLAB Editor that opens, add this function, which specifies that the librarymylibshould appear in the Library Browser with the nameMy Library.

    functionblkStruct = slblocks% This function specifies that the library 'mylib'% should appear in the Library Browser with the% name 'My Library'Browser.Library ='mylib';% 'mylib' is the name of the libraryBrowser.Name ='My Library';% 'My Library' is the library name that appears% in the Library BrowserblkStruct.Browser = Browser;

  7. Save the function asslblocks.m.

    Note

    You can save the function as an.mor.mlxfile. You cannot save it as a P-code file.

  8. Open the Library Browser by clicking自由rary Browserin the Simulink Toolstrip.

  9. To see the new library in the Library Browser, right-click the library list and select刷新库浏览器.

    The figure shows the example librarymylib库浏览器名称My Library.

Note

If you saved your library without setting'EnableLBRepository'to'on', a message appears at the top of the Library Browser.

ClickFixand respond to the prompt as appropriate.

Add Sublibrary to the Library Browser

Follow these steps to add a sublibrary namedmylib2to yourmyliblibrary.

  1. Create a library namedmylib2. Add some blocks to it.

  2. In the MATLAB Command Window, set theEnableLBRepositorylibrary property to'on'for the new library.

    set_param(gcs,'EnableLBRepository','on');
  3. Savemylib2to the folder that containsmylib.

  4. Add aSubsystemblock to themyliblibrary.

  5. Remove the input and output ports from the subsystem by deleting theInportandOutportblocks inside the subsystem.

  6. 的名字SubsystemblockMy Sublibrary.

  7. To link theSubsystemblock to the sublibrary, set theOpenFcncallback tomylib2by using the Property Inspector.

    The Property Inspector lets you set the OpenFcn callback on the Properties tab.

  8. Savemylib.

  9. To see the new sublibrary in the Library Browser, right-click the library list and select刷新库浏览器.

    The figure shows the example sublibrarymylib2库浏览器名称My Sublibrary.

    Because of the callback you created, clickingMy Sublibrarydisplays the contents of themylib2library.

Specify Library Order in the Library List

You can specify the order of your library relative to the other libraries in the list by adding asl_customization.mfile to the MATLAB path and setting the sort priority of your library. For example, to see your library at the top of the list, you can set the sort priority to-2. By default, the sort priority of the Simulink library is-1. The other libraries have a sort priority of0by default, and these libraries appear below the Simulink library. Libraries with the same sort priority appear in alphabetical order.

This sample content of thesl_customization.mfile places the new library at the top of the list of libraries.

functionsl_customization(cm)% Change the order of libraries in the Simulink Library Browser.厘米。自由raryBrowserCustomizer.applyOrder({'My Library',-2});end

To make the customization take effect immediately, in the MATLAB Command Window, enter:

sl_refresh_customizations

My Library appears at the top of the list of libraries.

Related Topics