Stuart’s MATLAB Videos

Watch and Learn

Creating a custom data cursor 12

Posted by Doug Hull,

This video shows how to make a custom data cursor so that when you click on a data point, it will show you the information you want about that data. Also, this video demonstrates a technique for using varargin to pass inputs from one function to another.

Get Adobe Flash player .

12 CommentsOldest to Newest

bob replied on : 2 of 12

How do you make a custom data cursor function?

I’d like to be able to return the data cursor position to my other functions

bob replied on : 4 of 12

Ok, I figured it out.

Made the figure handle visible to other callbacks.
Had to edit the data-tip update function to pass in the handle to the figure (since it’s not a callback).
Then setappdata the data-tip-position in the update-function using the figure handle.

And voila, can access data-tip-position in other callbacks of my GUI.

That’s what I meant. Couldn’t get getCursorInfo to work properly.

Anyway, cool video, it helped point me in the right direction.

L Graves replied on : 5 of 12

A question I have is concerning getting cursor position when using multiple Y axis. I call and set currentaxis then click on datacursor and the y value is always the 1st axis.

Doug replied on : 6 of 12

They are stacked on top of one another. You need to turn hittest off for the one on top for the second one to ‘see’ the click.


Jette replied on : 7 of 12

Thank you very much for this video.

I still habe one question:
As far as I understand it, there is only one data-tip update function per figure. If I have a figure with several axes on it which have different kind data (and different plot types), is there a possibility to create a different output for different axes?

Doug replied on : 8 of 12


You would just have to make that function more self-aware as to who called it.


Audrey replied on : 9 of 12

I’m also interested in creating datatips with different output formats for different axes.

Could you please explain what you mean by “more self-aware”?


Corey Hobbs replied on : 10 of 12

If if wanted to change the x-axis cursor readout to ‘short’ format how would I do that? Currently my x-axis value is in shortE format when it displays in the cursor box, but I simply want it to display in a normal format.

Seb replied on : 12 of 12

I would like to get the specific colour of a line. Furthermore I would like to use this information to add in the datatip.
In my multiplot every line have his unique color.
While plotting sometimes around 20 lines I would like to have this additional information. I have a legend but with 15 lines it is sometimes could confusing. By adding the additonal information about the specific name of the line via the colour information would it make more helpful. Is it possible to combine somehow?

Thanks in advance

Add A Comment

What is 5 + 9?

Preview: hide