Main Content

Define System Object for Use in金宝app

Develop System Object for Use in MATLAB System Block

You can develop a System object™ for use in a System block and interactively preview the block dialog box. This feature requires Simulink®.

With theSystem Blockediting options, the MATLAB®编辑器将预定义的代码插入到系统object. This coding technique helps you create and modify your System object faster and increases accuracy by reducing typing errors.

Using these options, you can also:

  • View and interact with the block dialog box design as you define the System object.

  • Add dialog box customization methods. If the block dialog box is open when you make changes, the block dialog design preview updates the display on saving the file.

  • Add icon methods. However, these elements display only on theMATLAB Systemblock in Simulink, not in thePreview Block Dialog.

Define Block Dialog Box for Plot Ramp

  1. Create a System object using the menu optionNew>System Object>Simulink Extension.

  2. Name the System objectPlotRampand save the file. This name becomes the block dialog box title.

  3. Delete the comment at the beginning of the file and replace it with the block description.

    % Display a button to launch a plot figure.

    This comment becomes the block parameters dialog box description, under the block title.

  4. SelectSystem Block>Preview Block Dialog. The block dialog box displays as you develop the System object.

  5. Add a ramp limit by selectingInsert Property>Numeric. Then change the property name and set the value to10.

    properties (Nontunable) RampLimit = 10;end
  6. Locate thegetPropertyGrouplsImplmethod using theAnalyzebutton.

    functiongroup = getPropertyGroupsImpl% Define property section(s) for System block dialoggroup = matlab.system.display.Section(mfilename('class'));end
  7. Create the group for theVisualizeaction.

    functiongroup = getPropertyGroupsImpl% Define property section(s) for System block dialoggroup = matlab.system.display.Section(mfilename('class')); group.Actions = matlab.system.display.Action(@(~,obj)...visualize(obj),'Label','Visualize');end
  8. Add a function that adds code to display theVisualizebutton on the dialog box.

    methodsfunction可视化(obj) figure; d = 1:obj.RampLimit; plot(d);endend
  9. As you add elements to the System block definition, save your file. Observe the effects of your code additions to the System block definition.

    TheSystem Blockmenu also displays checks next to the methods included in your file.

  10. Delete any unused methods in the template or modify the methods to further customize the System object and System block. The class definition file now has all the code necessary for thePlotRampSystem object.

    classdefPlotRamp < matlab.System% Display a button to launch a plot figure.properties(Nontunable) RampLimit = 10;endmethods(Static, Access=protected)functiongroup = getPropertyGroupsImpl group = matlab.system.display.Section(mfilename('class')); group.Actions = matlab.system.display.Action(@(~,obj)...visualize(obj),'Label','Visualize');endendmethodsfunction可视化(obj) figure; d = 1:obj.RampLimit; plot(d);endendend

After you complete your System block definition, save it, and then load it into a MATLAB System block in Simulink.

Related Topics