Main Content

matlab.system.display.Actionclass

Package:matlab.system.display
Superclasses:

Custom button

Syntax

matlab.system.display.Action(action)
matlab.system.display.Action(action,Name,Value)

Description

matlab.system.display.Action(action)specifies a button to display on theMATLAB Systemblock. This button executes a function by launching a System object™ method or invoking any MATLAB®function or code.

A typical button function launches a figure. The launched figure is decoupled from the block dialog box. Changes to the block are not synced to the displayed figure.

You definematlab.system.display.Actionwithin thegetPropertyGroupsImplmethod in your class definition file. You can define multiple buttons using separate instances ofmatlab.system.display.Actionin your class definition file.

matlab.system.display.Action(action,Name,Value)includesName,Valuepair arguments, which you can use to specify any properties.

Input Arguments

action

Action taken when the user presses the specified button on theMATLAB Systemblock dialog. The action is defined as a function handle or as a MATLAB command. If you define the action as a function handle, the function definition must define two inputs. These inputs are amatlab.system.display.ActionDataobject and a System object instance, which can be used to invoke a method.

Amatlab.system.display.ActionDataobject is the callback object for a display action. You use theUserDataproperty ofmatlab.system.display.ActionDatato store persistent data, such as a figure handle.

Name-Value Pair Arguments

Specify optional comma-separated pairs ofName,Valuearguments.Nameis the argument name andValueis the corresponding value.Namemust appear inside quotes. You can specify several name and value pair arguments in any order asName1,Value1,...,NameN,ValueN.

Properties

You specify these properties as part of the input usingName,Valuepair arguments. Optionally, you can define them usingobject.propertysyntax.

  • ActionCalledFcn— Action to take when the button is pressed. You cannot specify this property using a Name-Value pair argument.

  • Label- Text to display on the button. The default value is an empty character vector.

  • Description- Text for the button tooltip. The default value is an empty character vector.

  • Placement— Character vector indicating where on a separate row in the property group to place the button. Valid values are'first','last', or a property name. If you specify a property name, the button is placed above that property. The default value is'last'.

  • Alignment— Character vector indicating how to align the button. Valid values are'left'and'right'. The default value is'left'.

Examples

collapse all

Define aVisualize按钮,其associated function to open a figure that plots a ramp using the parameter values in the block dialog.

methods(Static,Access = protected)functiongroup = getPropertyGroupsImpl group = matlab.system.display.Section(mfilename('class')); group.Actions = matlab.system.display.Action(@(~,obj)...visualize(obj),'Label','Visualize');endendmethodsfunctionobj = PlotRamp(varargin) setProperties(obj,nargin,varargin{:});endfunctionvisualize(obj) figure; d = 1:obj.RampLimit; plot(d);endend

When you specify the System object in theMATLAB System(Simulink)block, the resulting block dialog box appears as follows.

To open the same figure, rather than multiple figures, when the button is pressed more than once, use this code instead.

methods(Static,Access = protected)functiongroup = getPropertyGroupsImpl group = matlab.system.display.Section(mfilename('class')); group.Actions = matlab.system.display.Action(@(actionData,obj)...visualize(obj,actionData),'Label','Visualize');endendmethodsfunctionobj = ActionDemo(varargin) setProperties(obj,nargin,varargin{:});endfunctionvisualize(obj,actionData) f = actionData.UserData;ifisempty(f) || ~ishandle(f) f = figure; actionData.UserData = f;elsefigure(f);% Make figure currentendd = 1:obj.RampLimit; plot(d);endend