From: Matthew on
I was looking for a way to do exactly this. Thank you.

"Dan Sternberg" <dsternbeNO(a)SPAMmathworks.com> wrote in message <f2hmja$4hd$1(a)fred.mathworks.com>...
> Hi Brian,
>
> Would replacing the line
>
> nam = 'Brian';
> with
> tar = get(event_obj,'Target');
> nam = get(tar,'DisplayName');
>
> be sufficient for your needs?
>
> -I hope this helps.
> Dan
>
> ---
> Dan Sternberg
> The MathWorks, Inc.
>
> "Brian T" <brian.af.taylor(a)aero.bombardier.com> wrote in message
> news:ef573af.-1(a)webcrossing.raydaftYaTP...
> >I am trying to customize the display of the data cursor datatip as
> > shown below. Rather than hardcoding the data name, I would like to
> > use the 'DisplayName' from the data. That way if I have to data sets
> > plotted it will show me the name of the select set. Note: if you use
> > 'window' DisplayStyle for the data cursor, the 'Title' of the window
> > panel is set to the data 'DisplayName' - this is what I want to
> > "extract"
> >
> > % doc_datacursormode.m
> > function doc_datacursormode
> > fig = figure;
> > a = -16; t = 0:60;
> > plot(t,sin(a*t),'DisplayName','Brian')
> > dcm_obj = datacursormode(fig);
> > set(dcm_obj,'DisplayStyle','datatip',...
> > 'SnapToDataVertex','on','Enable','on')
> > set(dcm_obj,'UpdateFcn',@myupdatefcn)
> >
> > % Click on line to select data point
> >
> > function txt = myupdatefcn(empt,event_obj)
> > pos = get(event_obj,'Position');
> > nam = 'Brian';
> > txt = {[nam],['Time: ',num2str(pos(1))],...
> > ['Amplitude: ',num2str(pos(2))]};
> > %end
>
>