安装了matlab2014b后,突然发现Simulink Library Browser窗口中没有内容,找了一种方法添加进去,希望对有需要的朋友有所帮助!# t3 ?9 l! k! J( n$ b; D
1、创建库文件:打开Simulink Library Browser窗口。要建立Simulink库文件,首先启动Simulink工作窗口,单击菜单栏【File】下的【New】选项,选择【library】选项, 打开一个新的Library窗口界面,此时,用户可以将自己需要添加的一些模块加入到新的窗口中。然后保存为Own_efinition.mdl(所需要定义的库文件名称)。这样,就建立了一个 自定义的库文件。 $ c2 S# A# g& t5 B- A# j2、在Matlab路径下创建存放库文件的路径,也即自定义的模块库在Library Browser下的显示位置。注意在Matlab中,每一个模块库文件所在的路径必须不同。 5 e. f) E+ o2 ~+ Z' x* D4 S创建的Maltab路径是:Drogram FilesMATLABR2011btoolboxSimulinkSimulinkMyLibrary(根据自己的Matlab安装路径来确定),其中MyLibrary为自定义的文件夹。 R2 g& v r( |$ j7 J
3、将第一步中建立的库文件拷贝到新建的Matlab路径下。在Matlab主窗口的【File】菜单栏下选择【Set Path】选项,然后单击【Add Folder】按钮,将新建的 路径添加进来,然后保存(Save),退出(Close)。 ' `0 I0 Z9 E% `5 e( ^4 E1 I) Z4、要显示自定义的模块库,还需要拷贝slblocks.m函数到新建的路径下。在Matlab的命令窗口中输入: 5 Q" `9 M0 W u
>> which('slblocks.m', '-all') - w0 _0 p) S5 l0 m( x) F
>> open('Drogram FilesMATLABR2011btoolboxSimulinkSimulinkblocksslblocks.m') - `8 k2 _. J, H2 t9 F ) H4 ^% s! ^6 ?0 P6 S这样就可以打开slbocks.m文件模板,为了将自定义的模块库显示在Library Browser窗口下,需要对该程序进行修改。首先把slbocks.m文件拷贝到自定义库文件 ; J! H$ c2 X1 E同一目录下(即刚才创建的路径),然后打开该文件进行如下修改(红色为所作修改),并保存: 8 D# S' A9 t5 u5 i$ _function blkStruct = slblocks 4 b! M- P# y! H% o6 {4 Q* s9 s; m%SLBLOCKS Defines the block library for a specific Toolbox or Blockset. % SLBLOCKS returns information about a Blockset to Simulink. The % information returned is in the form of a BlocksetStruct with the % following fields: % $ Z0 z+ j3 B# e
% Name Name of the Blockset in the Simulink block library % Blocksets & Toolboxes subsystem. % W H% F5 J7 j, p" H$ n: k
% OpenFcn MATLAB expression_r(function) to call when you % double-click on the block in the Blocksets & Toolboxes % subsystem. - ?) \/ j" k+ X3 X& v3 F$ w0 G4 r6 ]
% MaskDisplay Optional field that specifies the Mask Display commands % to use for the block in the Blocksets & Toolboxes % subsystem. ( z j8 y. h/ ^' \% Browser Array of Simulink Library Browser structures, described % below. % R, l! v9 h2 T/ a* ~
, c; W3 ], x' a. r1 @8 P+ B- C
; |% w& L: \% S$ [; Q
2 ~. R, g$ f2 g0 p% r k6 D
# K) @8 }- j, |) Z" R& i5 H
' w: j! l+ ~) o- L: h: ~9 Y
o& X5 c. G" g$ Q+ `& ?3 O0 C D* c( L
3 T" c: N- P$ z% & r* j1 F5 L6 E7 U' ]4 e
% The Simulink Library Browser needs to know which libraries in your % Blockset it should show, and what names to give them. To provide % this information, define an array of Browser data structures with one % array element for each library to display in the Simulink Library % Browser. Each array element has two fields: % S/ c9 F; Z' k$ p# {8 c; m) y% Library File name of the library (mdl-file) to include in the % Library Browser. - a6 d9 ~2 R3 f( O* X; r
% Name Name displayed for the library in the Library Browser % window. Note that the Name is not required to be the % same as the mdl-file name. % : ~) U( i/ P% ]0 j! y
% Example: % % % , q- L3 F: L$ A/ x R. j
% % Define the BlocksetStruct for the Simulink block libraries % % Only simulink_extras shows up in Blocksets & Toolboxes % % 7 W- I l: z! c* Q% blkStruct.Name = ['Simulink' sprintf('n') 'Extras']; % blkStruct.OpenFcn = 'simulink_extras'; 0 L# M; Q0 R+ m7 X# S
% blkStruct.MaskDisplay = sprintf('SimulinknExtras'); % % % % z: L. N4 |+ w m9 X1 P; }
% % Both simulink and simulink_extras show up in the Library Browser. % % 5 i1 f/ K6 Q9 P$ i, s
% blkStruct.Browser(1).Library = 'simulink'; % blkStruct.Browser(1).Name = 'Simulink'; % blkStruct.Browser(2).Library = 'simulink_extras'; % blkStruct.Browser(2).Name = 'Simulink Extras'; % 1 r6 W9 g- ?( ^% Copyright 1990-2006 The MathWorks, Inc. % $Revision: 1.20.2.10 $ % + ?1 ~2 [3 u9 H% Name of the subsystem which will show up in the Simulink Blocksets 8 p% E7 n$ P+ m" r3 j" K
" s v @- K3 u- ? , k% v5 D& ^$ S0 w% i8 ]& \) d. K" c" @( g Q
% and Toolboxes subsystem. % 8 u8 @$ n' ` ?
blkStruct.Name = ['Simulink' sprintf('n') 'Extras']; % + C/ A/ N' S) E" ^' ~9 D% The function that will be called when the user double-clicks on % this icon. % 8 S. `" G( t+ X8 ~& f+ nblkStruct.OpenFcn = 'simulink_extras'; % 8 A ?# [- [0 y, H4 b2 \" e
% The argument to be set as the Mask Display for the subsystem. You % may comment this line out if no specific mask is desired. % Example: blkStruct.MaskDisplay = 'plot([0:2*pi],sin([0:2*pi]));'; % No display for Simulink Extras. % & [) R# d; u5 x- c) \8 d
blkStruct.MaskDisplay = ''; % + R) u! b: r5 a/ v$ S' B& R/ R% Define the Browser structure array, the first element contains the % information for the Simulink block library and the second for the % Simulink Extras block library. % ) b: C2 U8 L3 r9 L9 v" N
Browser(1).Library = 'Own_efinition'; %这个是库文件名 8 Q% L* \5 e4 j2 O
Browser(1).Name = 'MyLibrary'; %这个是需要在库浏览器中显示的名称 Browser(1).IsFlat = 0;% Is this library "flat" (i.e. no subsystems)? Browser(2).Library = 'simulink_extras'; Browser(2).Name = 'Simulink Extras'; . G* F$ C6 j7 ?( U3 M) N! S
Browser(2).IsFlat = 0;% Is this library "flat" (i.e. no subsystems)? blkStruct.Browser = Browser; clear Browser; % $ H' l$ v! K0 i. ~" ~, ]& |# z* M% Define information about Signal Viewers % 1 o3 \8 o5 ?9 j8 t7 A) A3 xViewer(1).Library = 'simviewers'; Viewer(1).Name = 'Simulink'; blkStruct.Viewer = Viewer; clear Viewer; 9 @) L, a, |; e6 p; Q4 J; C8 Q 2 d6 C( C0 g+ g9 r0 C : L: ]. F6 Q. _& w5 W G! Z
% * m e' O0 H# U0 [0 G6 I% Define information about Signal Generators % # t8 e' t/ ?/ k J; a# ~! x1 P
Generator(1).Library = 'simgens'; Generator(1).Name = 'Simulink'; blkStruct.Generator = Generator; clear Generator; ! j6 }' Q6 _+ F4 W% Define information for model updater 1 m7 t1 M+ ]% Z+ |6 K1 r& F$ h, ?: |%blkStruct.ModelUpdaterMethods.fhDetermineBrokenLinks = @UpdateSimulinkBrokenLinksMappingHelper; & a# [. b0 u' j% @blkStruct.ModelUpdaterMethods.fhSeparatedChecks = @UpdateSimulinkBlocksHelper; % End of slblocks 3 N9 T9 o0 W9 ]& ~
5、再打开Simulink Library Browser,按F5刷新,即可看到自定义的模块库,展开后可以看到内部的自定义模块。那么用户可以方便地进行拖放模块,就可以使用 自定义的封装模块了。 2 k( e$ K& b; c! o+ O
如果还要在新建的模块库下面创建子模块库,需要把Subsystem模块加入到模块库中,打开Subsystem模块,删除所有内容(ports等元件),添加自己创建的模块 2 a% z0 e* L0 v" i
保存即可,然后重新打开Simulink Library Browser,按F5刷新,即可看到自定义的模块库和字模块库。 N: D V% F; n- m5 Y
, A% | F m1 @
2 f; ?/ F! M f8 h; Z' A