This example shows how to create a block library and add it to the Simulink® Library Browser.
In the Simulink Editor, click File > New > Library.
Simulink creates an untitled library.
Drag blocks from models or other libraries into the new library. You can modify the blocks in the library by changing block parameters, adding masks, or grouping blocks in subsystems.
Save the library in a folder that is on the MATLAB® path.
Note: To add a folder to the MATLAB path, right-click the folder in MATLAB, and click Add to Path > Selected Folders and Subfolders.
Open the library and unlock it by clicking Diagram > Unlock Library.
At the MATLAB command line, enable the model property
that Simulink can add the library to the Library Browser.
In MATLAB, open the folder containing the library and right-click and select New File > Script.
Save the file as
slblocks.m, and add this function
function blkStruct = slblocks % This function specifies that the library should appear % in the Library Browser % and be cached in the browser repository Browser.Library = 'mylib'; % 'mylib' is the name of the library Browser.Name = 'My Library'; % 'My Library' is the library name that appears in the Library Browser blkStruct.Browser = Browser;
slblocks.m file allows you to control
how Simulink displays your library. For example, you can specify
the location of your library in relation to other libraries. You can
also display your library as a sublibrary.
To view sample code snippets that allow this type of control,
view the code and comments in the
in the folder
Save the file
slblocks.m. Open the Library
Browser and refresh it to view your library.