1、在 Simulink Start Page 上,选择 Blank Library 并点击 Create Library。
2、向库中添加一个 Gain 模块和两个 Subsystem 模块。将两个 Subsystem 模块分别命名为 sys1 和 sys2。在 sys2 属性中,将 OpenFcn 回调设置为 mylib2。
3、在 MATLAB命令行中,输入以下命令以启用模型属性 EnableLBRepository。当保存库时,只有此属性设置为 on,创建的库才会出现在浏览器中。
set_param(gcs,'EnableLBRepository','on');
4、将库保存到 MATLAB 路径上的文件夹中。对于本示例,将库命名为 mylib,再创建一个库 mylib2,然后添加一些模块。
5、将 mylib2 保存到与 mylib 相同的文件夹中。
6、在当前路径下,创建一个脚本,将文件命名为 slblocks.m
7、打开 slblocks.m。将此函数添加到其中并保存。
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;
8、在 Library Browser 中,执行刷新操作以查看新库。右键点击库列表并选择 Refresh Library Browser。
下图显示了示例库 mylib,它在 Library Browser 中的名称为 My Library
注意: