主要内容

定制MATLAB系统块对话框

这个例子向您展示了如何定制一个MATLAB系统块的对话框。

系统对象

系统对象允许您使用MATLAB实现算法。系统对象是一种特殊的MATLAB对象,专门为实现和模拟动态系统随时间变化的输入。

定义一个系统对象后,您可以包括在使用MATLAB仿真软件模型系统。金宝app

模型描述

这个例子包含一个MATLAB系统块,实现了系统对象清单中。使用MATLAB系统块对话框来修改系统对象的属性。这个例子展示了如何自定义提示属性以及如何创建复选框、列表、团体、标签和按钮的对话框。

系统对象类定义

您可以访问MATLAB源代码使用MATLAB系统阻止通过单击“源代码”超链接块对话框。系统对象清单中实现了getPropertyGroupsImplgetHeaderImpl方法用于自定义块对话框的外观和组织系统对象属性。

  1. PropertyDefault——没有定制属性

  2. PropertyCustomPrompt——属性自定义提示

  3. PropertyEnum——枚举属性与一个有限的选项列表

  4. PropertyLogical——属性的验证逻辑创建复选框

  5. PropertyInDifferentTab——属性显示在对话框的一个不同的选项卡

getPropertyGroupsImpl方法使用matlab.system.display。节和matlab.system.display。SectionGroup类来创建属性部分和对话框中的选项卡。getPropertyGroupsImpl还创建一个按钮调用的“组2”一节可视化方法系统的对象。

classdef清单< matlab。%清单中定制系统块对话框属性PropertyDefault PropertyDefault = 10%,上面没有评论,使用属性名%作为提示% PropertyCustomPrompt使用上面评论属性自定义提示PropertyCustomPrompt = 20% PropertyEnum使用枚举值限制在有限列表PropertyEnum (1, 1) ColorValues = ColorValues。蓝色% PropertyInDifferentTab使用getPropertyGroupsImpl创建标签PropertyInDifferentTab = 30结束属性(Nontunable) % PropertyLogical使用逻辑属性验证创建一个复选框%逻辑属性需要Nontunable用于仿真软件PropertyLogical(1,1)逻辑= true结束方法(访问=保护)函数y = stepImpl (~ u) y = u;金宝app结束结束方法(静态访问=保护)函数组= getPropertyGroupsImpl % %对话框中使用getPropertyGroupsImpl创建属性部分。创建两个部分以标题“Group1”和% Group2。包含PropertyDefault和% PropertyCustomPrompt Group1。“Group2”包含PropertyEnum、% PropertyLogical和可视化按钮。group1 = matlab.system.display.Section (…“标题”、“组1”,…PropertyList, {‘PropertyDefault’,‘PropertyCustomPrompt});group2 = matlab.system.display.Section (… 'Title','Group 2',... 'PropertyList',{'PropertyEnum','PropertyLogical'}); % Add a button that calls back into the visualize method group2.Actions = matlab.system.display.Action(@(actionData,obj)... visualize(obj,actionData),'Label','Visualize'); tab1 = matlab.system.display.SectionGroup(... 'Title', 'Tab 1', ... 'Sections', [group1, group2]); tab2 = matlab.system.display.SectionGroup(... 'Title', 'Tab 2', ... 'PropertyList', {'PropertyInDifferentTab'}); groups = [tab1, tab2]; end function header = getHeaderImpl header = matlab.system.display.Header(mfilename('class'), ... 'Title','AlternativeTitle',... 'Text','Customize dialog header using getHeaderImpl method.'); end end methods function visualize(obj, actionData) % Use actionData to store custom data f = actionData.UserData; if isempty(f) || ~ishandle(f) f = figure; actionData.UserData = f; else figure(f); % Make figure current end d = 1:obj.PropertyCustomPrompt; plot(d); end end end

另请参阅

相关的话题