Path: news.mathworks.com!not-for-mail
From: "helper " <spamless@nospam.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Datatip (Datacursormode)
Date: Fri, 9 May 2008 22:20:17 +0000 (UTC)
Organization: Timothy S. Farajian, Inc.
Lines: 49
Message-ID: <g02in1$mhk$1@fred.mathworks.com>
References: <g00qvj$4gu$1@fred.mathworks.com> <g016ot$gva$1@fred.mathworks.com> <g02208$r3i$1@fred.mathworks.com>
Reply-To: "helper " <spamless@nospam.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1210371617 23092 172.30.248.35 (9 May 2008 22:20:17 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 9 May 2008 22:20:17 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1272923
Xref: news.mathworks.com comp.soft-sys.matlab:467650


"Daphne " <daphnew_too_nospam@yahoo.com> wrote in message 
<g02208$r3i$1@fred.mathworks.com>...
> 
> If you do find a way to mark the datatips I would 
> appreciate it. 


Ok.  I found a method.  Note that this is undocumented and 
is guaranteed to change in future releases, and I'm not 
sure what I am really doing, but it does work for now.

If you create a plot using:

  hPlot = plot(X,Y);

And you want to create a datatip at index "I" of the data, 
use the following command to get a handle to the datacursor:

 hDC = datacursormode;
 set(hDC,'Enable','off')

Then, use the following commands to create your datatip:

h = createDatatip(hDC, hPlot);
drawnow
set(h,'Position',[X(I) Y(I)],...
  'String',sprintf('X: %s\nY: %s',...
  num2str(X(I)),num2str(Y(I))));


However, if you want to create more than one datatip at a 
time, note that the next call to createDatatip messes 
things up for some reason.  Therefore, issue all 
createDatatip commands at first, then set the properties.  
For example:

I = [3 8];
for n = 1:length(I)
  h(n) = createDatatip(hDC, hPlot);
end
drawnow
for n = 1:length(I)
set(h(n),'Position',[X(I(n)) Y(I(n))],...
  'String',sprintf('X: %s\nY: %s',...
  num2str(X(I(n))),num2str(Y(I(n)))));
end

I found many variations and different methods, but this one 
seems to work.