在Simulink中創建庫


將Simulink中常用的block放入一個創建的庫中,調用起來會很方便。 本篇將介紹創建Simulink庫的基本方法。

1. 創建庫

庫的創建方法和Simulink模型非常相似。第一步是在庫瀏覽器(Library Browser)的菜單中,選中File→New→Library。

simulink_CreateNewLibrary

 

在彈出的創建庫窗口,添加該庫的blocks。

Blocks Added to a New Library.

命名並保存該庫到當前目錄。

2. 添加庫到Library Browser

找到matlabroot/toolbox/simulink/blocks/slblocks.m, 將該文件復制到當前目錄。

或直接在當前目錄中創建slblocks.m, 內容如下:

function blkStruct = slblocks 
% Function to add a specific custom library to the Library Browser 

% Author: Phil Goddard (phil@goddardconsulting.ca) 

% Define how the custom library is displayed in the Library Browser 
Browser.Library = 'customlib'; %庫文件的名稱 
Browser.Name    = 'My Custom Library'; %在庫瀏覽器中顯示的名稱 
Browser.IsFlat  = 1; % 該庫文件是否有子系統等 

% 定義在舊版matlab中的顯示方式e 
blkStruct.Name = ['My Custom' sprintf('\n') 'Library'];  %在庫瀏覽器中顯示的名稱 
blkStruct.OpenFcn = 'customlib'; % Name of the .mdl file   %庫文件的名稱 
blkStruct.MaskDisplay = ''; 

% 輸出創建的Browse到Simulink庫瀏覽器 
blkStruct.Browser = Browser;

 

3. 顯示庫

將當前目錄添加到MATLAB的路徑中: File->Set path->Add Folder->Save;

重啟MATLAB,在Simulink的庫瀏覽器中,即可找到剛所創建的庫。

simulink_CustomLibraryBrowser


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM