MATLAB Function Reference Previous page   Next Page
datacursormode

Enable/disable interactive data cursor mode

Syntax

Description

datacursormode on enables data cursor mode on the current figure.

datacursormode off disables data cursor mode on the current figure.

datacursormode toggles data cursor mode on the current figure.

datacursormode(figure_handle,...) enables or disables data cursor mode on the specified figure.

dcm_obj = datacursormode(figure_handle) returns the figure's data cursor mode object, which enables you to customize the data cursor. See Data Cursor Mode Object.

Data Cursor Mode Object

The data cursor mode object has properties that enable you to controls certain aspects of the data cursor. You can use the set and get commands and the returned object (dcm_obj in the above syntax) to set and query property values.

Data Cursor Mode Properties
Enabled                      on | off

Specifies whether this mode is currently enabled on the figure.

SnapToDataVertex             on | off

Specifies whether the data cursor snaps to the nearest data value or is located at the actual pointer position.

DisplayStyle                 datatip | window

Determines how the data is displayed.

Updatefcn                    function handle

This property references a function that customizes the text appearing in the data cursor. The function handle must reference a function that has two implicit arguments (these arguments are automatically pass to the function by MATLAB when the function executes). For example, the following function definition line uses the required arguments:

event_obj is an object having the following read-only properties.

You can query these properties within your function. For example,

returns the coordinates of the cursor.

See Function Handles for more information on creating a function handle.

See Change Data Cursor Text for an example.

Data Cursor Method

You can use the getCursorInfo function with the data cursor mode object (dcm_obj in the above syntax) to obtain information about the data cursor. For example,

returns a vector of structures, one for each data cursor on the graph. Each structure has the following fields:

Line and lineseries objects have an additional field:

Examples

This example creates a plot and enables data cursor mode from the command line.

Setting Data Cursor Mode Options

This example enables data cursor mode on the current figure and sets data cursor mode options. The following statements

Change Data Cursor Text

This example shows you how to customize the text that is displayed by the data cursor. Supose you want to replace the text displayed in the datatip and data window with "Time:" and "Ampltude:".


Previous page  daspect datatipinfo Next page

© 1994-2005 The MathWorks, Inc.