matlab中如何創建自己的模塊庫


matlab中如何創建自己的模塊和模塊庫 

參考:https://www.mathworks.com/help/simulink/ug/adding-libraries-to-the-library-browser.html

          https://www.mathworks.com/help/simulink/ug/creating-block-libraries.html

 

 1.首先創建一個空文件夾,最好放在matlab安裝文件中toolbox文件夾下

 

 2. 在matlab中打開該空文件夾

 

 3. 創建如下必要的函數

 

 

 代碼如下:

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; 

 

4.將該空文件夾保存到matlab路徑中去

 

 

5. 在simulink 中創建新的library ,並在其中創建三個空模塊(舉例的),或者自己創建的模塊

 

 

 

 

 

 6.在matlab命令行中運行如下命令

7.保存該library 文件到創建的空文件中,注意其名稱必須與前面設置的程序中的名稱一致

 

 

 

 8.就可以打開simulink中的模塊庫,刷新之后就可以看到自己創建的library

 

 

 

自己創建的library 在matlab模塊瀏覽器中位置默認是按照字母順序排列的,通過將sl_customization.m文件添加到MATLAB路徑並設置庫的排序優先級,可以指定列表中庫相對於其他庫的順序。例如,要在列表頂部看到自己設置的庫,可以將排序優先級設置為-2。默認情況下,Simulink庫的排序優先級為-1。默認情況下,其他庫的排序優先級為0,這些庫顯示在Simulink庫的下方。具有相同排序優先級的庫按字母順序顯示。

下面示例的sl_customization.m文件是將新庫放在庫列表的頂部。

function sl_customization(cm)
% Change the order of libraries in the Simulink Library Browser. 
cm.LibraryBrowserCustomizer.applyOrder({'My Library',-2});
end

要使設制立即生效,請在matlab命令欄輸入運行如下命令即可

 sl_refresh_customizations



 


免責聲明!

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



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