matlab.system.display.Action class

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 the MATLAB System block. 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 define matlab.system.display.Action within the getPropertyGroupsImpl method in your class definition file. You can define multiple buttons using separate instances of matlab.system.display.Action in your class definition file.

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

Input Arguments

action

Action taken when the user presses the specified button on the MATLAB System block 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 a matlab.system.display.ActionData object and a System object instance, which can be used to invoke a method.

A matlab.system.display.ActionData object is the callback object for a display action. You use the UserData property of matlab.system.display.ActionData to store persistent data, such as a figure handle.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Properties

You specify these properties as part of the input using Name,Value pair arguments. Optionally, you can define them using object.property syntax.

  • 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 a Visualize button and its associated function to open a figure that plots a ramp using the parameter values in the block dialog.

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

When you specify the System object in the MATLAB System 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)
  function group = getPropertyGroupsImpl
    group = matlab.system.display.Section(mfilename('class'));
    group.Actions = matlab.system.display.Action(@(actionData,obj)...
       visualize(obj,actionData),'Label','Visualize');
  end
end
    
methods
  function obj = ActionDemo(varargin)
    setProperties(obj,nargin,varargin{:});
  end
        
  function visualize(obj,actionData)
    f = actionData.UserData;
    if isempty(f) || ~ishandle(f)
      f = figure;
      actionData.UserData = f;
    else
        figure(f); % Make figure current
    end
        
    d = 1:obj.RampLimit;
    plot(d);
  end
end