MATLAB的Simulink常用模塊(一)

雲龍派 發佈 2024-04-26T04:36:49.731711+00:00

在MATLAB的Simulink中有些常用的模塊,今天主要介紹常數模塊、示波器模塊、以及模塊屬性的操作函數。1.模塊的構成元素輸入/輸出埠:作為模塊之間傳遞數據的紐帶,連接輸入信號和輸出信號。模塊外觀:通常為矩形或圓形,上面帶有說明文字或圖像並顯示有輸出/輸出埠名。

在MATLAB的Simulink中有些常用的模塊,今天主要介紹常數模塊、示波器模塊、以及模塊屬性的操作函數。


1.模塊的構成元素

輸入/輸出埠:作為模塊之間傳遞數據的紐帶,連接輸入信號和輸出信號。
模塊外觀:通常為矩形或圓形,上面帶有說明文字或圖像並顯示有輸出
/輸出埠名。
模塊對話框:雙擊模塊外觀後彈出的參數GUI,可以在參數控制項上進行參數設置。

2.Matlab/Simulink快捷鍵

2.1 模型調整

Alt + Enter:為選定模塊設置主要參數
Ctrl + Shift + I:打開或隱藏 Property Inspector
Shift + 拖動句柄:調整模塊大小,保持相同的高寬比
Ctrl + 拖動句柄:從中心調整模塊大小
Ctrl + R:順時針旋轉模塊 順時針旋轉90°
Ctrl + Shift + R:逆時針旋轉模塊
Ctrl + I:翻轉模塊
Ctrl + F:查找模塊
Ctrl + M:封裝模塊
Ctrl + U:在模塊封裝下查找
Ctrl + Shift + Y:注釋模塊
Ctrl + Shift + X:注釋掉或取消注釋模塊
Ctrl + K:刷新Mode模塊
Ctrl + L:對於連結模塊,轉到父模塊的庫
Ctrl + H:打開 Model Explorer

2.2 仿真鍵盤快捷鍵

Ctrl + E:打開 Configuration Parameters對話框
Ctrl + D:更新圖
Ctrl + T:開始仿真
Ctrl + Shift + T:停止仿真
Ctrl + B:構建模型(用於代碼生成)

2.3 調試和斷點鍵盤快捷方式

F10:步驟
F11:步入
Shift + F11:步出
F5:運行
F12:設置/清除斷點
Ctrl + J:查看simple time
視圖放大:r
視圖縮小:v

3.模塊的常用屬性和參數

clc;
clear all;
close all;
% 獲取模塊的屬性
% gcb:獲取當前被選中的模塊
% gcbh:獲取當前被選中的模塊的句柄
% get(handle):獲取模塊的屬性信息
% inspect(handle):通過屬性觀察器方式羅列模塊的屬性信息
% get_param(block,prop_string):獲取block模塊的prop_string屬性值
% set_param(block,prop_string,prop_value):將block模塊的prop_string屬性的值設為
% prop_value。prop_string,prop_value可以多對出現
open_system('test1')
information = gcb
get(gcbh)
set_param(gcbh,'BackgroundColor','c')
set_param(gcbh,'ForegroundColor','blue')
%set_param/get_param的第二個參數使用的不是提示標籤,而是參數的變量名。


information =


    'test1/Scope'


                                        Path: 'test1'
                                        Name: 'Scope'
                                         Tag: ''
                                 Description: ''
                                        Type: 'block'
                                      Parent: 'test1'
                                      Handle: 4.0430e+03
                             HiliteAncestors: 'none'
                             RequirementInfo: ''
                                    FontName: 'auto'
                                    FontSize: -1
                                  FontWeight: 'auto'
                                   FontAngle: 'auto'
                                    Selected: 'on'
                                    MaskType: ''
                             MaskDescription: ''
                                    MaskHelp: ''
                            MaskPromptString: ''
                             MaskStyleString: ''
                               MaskVariables: ''
                      MaskTunableValueString: ''
                          MaskCallbackString: ''
                            MaskEnableString: ''
                        MaskVisibilityString: ''
                           MaskToolTipString: ''
                          MaskVarAliasString: ''
                          MaskInitialization: ''
                          MaskSelfModifiable: 'off'
                                 MaskDisplay: ''
                            MaskBlockDVGIcon: ''
                               MaskIconFrame: 'on'
                              MaskIconOpaque: 'opaque'
                              MaskIconRotate: 'none'
                              MaskPortRotate: 'default'
                               MaskIconUnits: 'autoscale'
                             MaskValueString: ''
                    MaskRunInitForIconRedraw: 'analyze'
                           MaskTabNameString: ''
                                        Mask: 'off'
                               MaskCallbacks: {0×1 cell}
                                 MaskEnables: {0×1 cell}
                                   MaskNames: {0×1 cell}
                      MaskPropertyNameString: ''
                                 MaskPrompts: {0×1 cell}
                                  MaskStyles: {0×1 cell}
                           MaskTunableValues: {0×1 cell}
                                  MaskValues: {0×1 cell}
                         MaskToolTipsDisplay: {0×1 cell}
                            MaskVisibilities: {0×1 cell}
                              MaskVarAliases: {0×1 cell}
                             MaskWSVariables: []
                                MaskTabNames: {0×1 cell}
                                  MaskObject: []
                                       Ports: [1 0 0 0 0 0 0 0 0]
                                    Position: [345 129 375 161]
                                 Orientation: 'right'
                            PortRotationType: 'default'
                             ForegroundColor: 'black'
                             BackgroundColor: 'cyan'
                                  DropShadow: 'off'
                                      IOType: 'none'
                               NamePlacement: 'normal'
                                    ShowName: 'on'
                           HideAutomaticName: 'on'
                                    Priority: ''
                                   Commented: 'off'
                       CodeProfilingOverride: 'inherit'
                      AttributesFormatString: ''
                           InstantiateOnLoad: 'off'
                         PolySpaceEndComment: ''
                       PolySpaceStartComment: ''
                               AncestorBlock: ''
                              ReferenceBlock: ''
                           SourceLibraryInfo: ''
                              LibraryVersion: ''
                          UserDataPersistent: 'off'
                                    UserData: []
                            CompiledIsActive: 'on'
                                     RTWdata: []
                                     HDLData: []
                                 Diagnostics: ''
                            DialogParameters: [1×1 struct]
                   IntrinsicDialogParameters: [1×1 struct]
                         AlgorithmParameters: [1×1 struct]
                SecondaryAlgorithmParameters: [1×1 struct]
                          CompiledSampleTime: [-1 0]
                            InputSignalNames: {''}
                           OutputSignalNames: {1×0 cell}
                         ModelParamTableInfo: []
                StatePerturbationForJacobian: '1.0e-05'
    SCDEnableBlockLinearizationSpecification: 'off'
          SCDBlockLinearizationSpecification: []
                                     CopyFcn: ''
                                   DeleteFcn: ''
                               UndoDeleteFcn: ''
                                     LoadFcn: ''
                               ModelCloseFcn: ''
                                  PreSaveFcn: ''
                                 PostSaveFcn: ''
                                     InitFcn: ''
                                    StartFcn: ''
                                    PauseFcn: ''
                                 ContinueFcn: ''
                                     StopFcn: ''
                               NameChangeFcn: ''
                                ClipboardFcn: ''
                                  DestroyFcn: ''
                                  PreCopyFcn: ''
                                     OpenFcn: ''
                                    CloseFcn: ''
                                PreDeleteFcn: ''
                              ParentCloseFcn: ''
                                     MoveFcn: ''
                                   BlockType: 'Scope'
                            BlockDescription: 'Displays input signals with respect to simulation time'
                               BlockKeywords: ""
                                  LinkStatus: 'none'
                            StaticLinkStatus: 'none'
                            PortConnectivity: [1×1 struct]
                                 PortHandles: [1×1 struct]
                                 LineHandles: [1×1 struct]
                          CompiledPortWidths: [0×0 struct]
                      CompiledPortDimensions: [0×0 struct]
                       CompiledPortDataTypes: [0×0 struct]
                           CompiledPortUnits: [0×0 struct]
                  CompiledPortComplexSignals: [0×0 struct]
                       CompiledPortFrameData: [0×0 struct]
                   DataTypeOverride_Compiled: 'UseLocalSettings'
              MinMaxOverflowLogging_Compiled: 'UseLocalSettings'
                                Capabilities: [1×1 Capabilities]
                             IOSignalStrings: []
                               RuntimeObject: [0×1 double]
                         ExtModeUploadOption: 'none'
                     ExtModeLoggingSupported: 'on'
                          ExtModeLoggingTrig: 'off'
                   TargetArchitectureMapping: {}
                       OpenAtSimulationStart: 'off'
                             DisplayFullPath: 'off'
                               NumInputPorts: '1'
                      LayoutDimensionsString: '[1 1]'
                                  SampleTime: '-1'
                  FrameBasedProcessingString: 'Elements as channels (sample based)'
                                MaximizeAxes: 'Off'
                                 AxesScaling: 'Manual'
                       AxesScalingNumUpdates: '10'
                                    TimeSpan: 'Auto'
                       TimeSpanOverrunAction: 'Wrap'
                                   TimeUnits: 'None'
                           TimeDisplayOffset: '0'
                              TimeAxisLabels: 'Bottom displays only'
                           ShowTimeAxisLabel: 'off'
                         ActiveDisplayString: '1'
                                       Title: '%<SignalLabel>'
                                  ShowLegend: 'off'
                                    ShowGrid: 'on'
                        PlotAsMagnitudePhase: 'off'
                       ActiveDisplayYMinimum: '-10'
                       ActiveDisplayYMaximum: '10'
                                      YLabel: ''
                  DataLoggingLimitDataPoints: 'off'
                        DataLoggingMaxPoints: '5000'
                     DataLoggingDecimateData: 'off'
                       DataLoggingDecimation: '2'
                                 DataLogging: 'off'
                     DataLoggingVariableName: 'ScopeData'
                       DataLoggingSaveFormat: 'Dataset'


>> 

模塊的常用屬性

屬性名  作用說明
Path  模塊在模型中的路徑
Name  模塊的名字
ShowName  模塊的名字是否顯示出來
BlockType  模塊的類型名
Handle  模塊的句柄,double數據表示
Position  模塊的邊框在當前模型中的位置
ForegroundColor  模塊的前景色
BackgroundColor  模塊的背景色
Sample Time  模塊的採樣時間
FontAngle  字體斜度
FontName  字體名
FontSize  字體大小
FontWeight  字體粗度

4.常量模塊

常數模塊在仿真過程中通常輸出恆定的數值。常數模塊不僅支持scalar數據作為參數輸入,也支持向量、矩陣等多維數據。

提示標籤  參數的變量名
Constant value  價值
Interpret vector parameters as 1-D  將向量參數解釋為1-D
Sampling mode  採樣模型
Sample time  採樣時間
常數模塊、加減乘除四則運算和增益模塊及輸入輸出埠都擁有
Signal Attributes屬性配置界面。
Output minimum和Output maximum中默認為空,不對數據輸出進行任何檢測。
一旦設置了數值,模塊就會對輸出值進行檢查,當數值小於Output minimum
或者大於Output maximum時就會報錯來提醒用戶。 
Output data type對輸出數據的類型提供了一些選項。

5.示波器模塊

Scope模塊是示波器模塊,能夠顯示實數信號線。

(1) 修改Scope的輸入埠個數

雙擊示波器模塊,點擊File->-Number of input ports,修改輸入埠的個數為3。

(2)修改示波器的顯示布局的個數

點擊View->Configureation Properties->Number of input ports,將1修改成3。

(3)將示波器的數據輸出

點擊View->點擊Configureation Properties->點擊Logging->勾選Log data to workspace。

可以設置變量名(Variable name),選擇存儲到workspace中的存儲格式。
1.Structure With Time將Scope獲取到的採樣信號存儲在結構體中,
這個結構體包括:
(1)存儲時間序列的time
(2)存儲對應採樣時間點的採樣數據以及相關信息的結構體signals
(3)存儲模塊全路徑及名字的變量blockName
signals本身也是一個結構體,訪問採樣數據的方式
是ScopeData.signals.values,採樣數據按列排布。
ScopeData.time 存儲時間序列的time
ScopeData.signals.values 存儲對應採樣時間點的採樣數據。
2.Structure存儲類型少了time這個時間序列的存儲,其他成員相同。
3.Array為列向量方式存儲。
4.dataset 為數據集數組用於將異構數據和元數據(包括變量和觀察名稱)
收集到單個容器變量中。數據集數組適合存儲面向列的數據或表格數據,
這些數據通常以列的形式存儲在文本文件或電子表格中,並且可以容納
不同類型、大小、單位等的變量。

(4)示波器的動態參數和光標

Bilevel Measurements:用於測量輸入信號的過渡時間、超調、負調及周期。

Cursor Measurements:用於光標測量。

Signal Statistics:信號的統計數據。

Peak Finder:峰值查找器

(5)修改示波器坐標軸粗細、顏色、名稱、圖例、圖形顏色、標記點類型。

點擊view->點擊style或者Legend設置圖例

(6)將示波器圖像轉化為Figure,保存為其他格式圖像文件。

點擊File-> print to Figure

(7)給示波器添加編輯選項,編程方式設置

Scope波形顯示模塊實際上也是一個Figure窗口,隱藏了菜單欄的屬性,可以通過程序設置菜單欄,執行以下程序。

set(0,'ShowHiddenHandles','On')
set(gcf,'menubar','figure')

或者運行以下程序

shh = get(0,'ShowHiddenHandles');
set(0,'ShowHiddenHandles','On')
set(gcf,'menubar','figure')
set(gcf,'CloseRequestFcn','closereq')
set(gcf,'DefaultLineClipping','Off')
set(0,'ShowHiddenHandles',shh)

參考內容

[1] 博客園作者叮叮噹噹sunny的文章《Simulink仿真入門到精通(二) Simulink模塊 》,文章連結如下:https://www.cnblogs.com/dingdangsunny/p/12235689.html#_label0

[2] CSDN博主「小曾&同學」的文章《Matlab/Simulink快捷鍵》,文章連結如下:

https://blog.csdn.net/acknole/article/details/112344263

[3] CSDN博主 gameboy12615的文章《Matlab 示波器顯示設置》,文章連結為:

https://blog.csdn.net/gameboy12615/article/details/6056390?locationNum=14


本文內容來源於網絡,僅供參考學習,如內容、圖片有任何版權問題,請聯繫處理,24小時內刪除。


作 者 | 郭志龍

編 輯 | 郭志龍
校 對 | 郭志龍

關鍵字: