How can I implement a data cursor feature such that the data tip jumps by a specified amount if the Alt and Left/Right Arrow keys are pressed?

2 views (last 30 days)
I use the data cursor a lot in my figures and plots.  In order to save time, how can I use the data cursor such that the following parameters are met?
1. A LeftArrow press moves the data tip by 1 to the left.
2. A Alt+LeftArrow press moves the data tip by a specified number to the left.
3. A RightArrow press moves the data tip by 1 to the right.
4. A Alt+RightArrow press moves the data tip by a specified number to the right.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 2 Sep 2021
Edited: MathWorks Support Team on 27 Sep 2021
While MATLAB does not offer such a built-in feature, this behavior can be implemented using the 'KeyPressFcn' callback function of a figure.
 
As a demonstration of how to implement this feature, please refer to the example in the attached MATLAB file.  Please download the file and run it in MATLAB.  The number in the box displayed in the figure can be altered to any desired number to achieve the required jump size; by default, the step size is 24.  To move the data cursor by 1, use the left/right arrow keys.  To move the data cursor by the specified jump size, use the Alt+LeftArrow and Alt+RightArrow combination. 
 
For details of the implementation, please refer to the file.  The comments in the file give details about each line of code in the example.
 
For more information about the 'KeyPressFcn' callback function of a figure, please refer to the following link:
 
https://www.mathworks.com/help/matlab/ref/matlab.ui.figure-properties.html
 
For more information about 'datacursormode', please refer to the following link:
 
https://www.mathworks.com/help/matlab/ref/matlab.graphics.shape.internal.datacursormanager.html
 
 

More Answers (0)

Categories

Find more on Graphics Object Identification in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!