Datatip

14 views (last 30 days)
Slobodan Djordjevi?
Slobodan Djordjevi? on 12 Dec 2011
Answered: Thomas Flick on 31 May 2018
Hello!
I have a question regarding datatip on my GUI graph. Everytime I run my GUI and select Data Cursor I have to right click on graph and select my datatip file. The graph opens up the default one(X : xxxx, Y : yyyy). Mine shows date and mass. It's just a bit annoying opening up everytime... Can I change this by making it default for this GUI file?
Thank you in advance!

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 12 Dec 2011
I assume you have your data tip function, you can set it when you enable the data cursor mode.
%%Original data
f=figure;
h=plot(rand(10,1));
dcm=datacursormode(f);
datacursormode on;
set(dcm,'updatefcn',@MyDataTipFunction);
  4 Comments
Slobodan Djordjevi?
Slobodan Djordjevi? on 12 Dec 2011
I'm sorry. I don't understand this. In my data cursor file/function, I have figure and plot. I should leave that alone, cause it is working if I plot(rand(5))... But in Gui if I let plot(...) be just plot, nothing happens... I'm a bit disoriented... :) thanks for the help by the way...
Fangjun Jiang
Fangjun Jiang on 12 Dec 2011
Your GUI graph is already a figure. So when you enable its data cursor mode, you need to get the handle of your GUI graph, then do the dcm=datacursormode(FigureHandle) and then set(dcm,...).

Sign in to comment.

More Answers (3)

Slobodan Djordjevi?
Slobodan Djordjevi? on 12 Dec 2011
If I understand correctly, my GUI's name is goliGUI = FigureHandle
function datumplot(varargin)
goliGUI = figure
plot(varargin{:})
dcm = datacursormode(goliGUI);
datacursormode on
set(dcm, 'updatefcn', @myfunction)
function output_txt = myfunction(obj,event_obj... *etc*.
File's name is datumplot.m.
  3 Comments
Slobodan Djordjevi?
Slobodan Djordjevi? on 13 Dec 2011
So I have to go to my GUI and replace plot with datumplot and it should work?
Slobodan Djordjevi?
Slobodan Djordjevi? on 13 Dec 2011
If I do this, my GUI creates a separate window(Figure1) and data cursor is on and shown correctly. How do I keep it in my GUI? Walter said something about not to use figure?

Sign in to comment.


Slobodan Djordjevi?
Slobodan Djordjevi? on 13 Dec 2011
I did it...
Now I understand. My GUI is a figure itself. So my code now works and looks like this :
function datumplot(varargin)
fh = goliGUI
plot(varargin{:})
dcm = datacursormode(fh);
datacursormode on
set(dcm, 'updatefcn', @myfunction)
function output_txt = myfunction(obj,event_obj)...etc.
Thank you Walter and Fangjun, you really helped me.

Thomas Flick
Thomas Flick on 31 May 2018
This is an old post but as far as I can tell the problem has not been satisfactorily solved in that there is no proposed solution that is as easy as setting a default. Here is one that is that easy:
(1) Make a new shortcut or favorite. This requires a fairly new version of Matlab.
(2) Copy/paste this code into your favorite:
dcm=datacursormode(gcf);
datacursormode on;
set(dcm,'updatefcn',@MyDataTipFunction);
(3) While viewing your plot, click on your "favorite" button. This puts the plot in data cursor mode using your data tip function.

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!