http://www.mathworks.com/matlabcentral/newsreader/view_thread/329072
MATLAB Central Newsreader  gname problem
Feed for thread: gname problem
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Sat, 18 May 2013 13:22:10 +0000
gname problem
http://www.mathworks.com/matlabcentral/newsreader/view_thread/329072#904624
Stan24
Hi,<br>
Can anyone explain how to add case names to plot:<br>
<br>
h1 = plot(1:10, sin(1:10), 'o');<br>
hold on; <br>
h2 = gscatter(10*rand(1, 10), 2*rand(1,10), 1:10);<br>
hold off;<br>
<br>
gname(1:10, h1); <br>
<br>
Thanks,<br>
Stan

Sat, 18 May 2013 14:19:10 +0000
Re: gname problem
http://www.mathworks.com/matlabcentral/newsreader/view_thread/329072#904626
Stan24
I've forgotten to add:<br>
gname(1:10, h1); % returns the wrong handle

Wed, 22 May 2013 20:53:01 +0000
Re: gname problem
http://www.mathworks.com/matlabcentral/newsreader/view_thread/329072#904794
Tom Lane
> I've forgotten to add:<br>
> gname(1:10, h1); % returns the wrong handle<br>
<br>
I just tried this. If I type<br>
<br>
hh = gname(1:10, h1);<br>
<br>
and then I click points on the plot, only point with handles in h1 get <br>
labeled. The return value hh is a vector of handles to the text labels. So <br>
for example,<br>
<br>
set(hh,'color','m')<br>
<br>
turns the text magenta. This appears to be working correctly. What do you <br>
see that seems wrong?<br>
<br>
 Tom

Wed, 22 May 2013 22:08:09 +0000
Re: gname problem
http://www.mathworks.com/matlabcentral/newsreader/view_thread/329072#904798
Stan
Hi Tom,<br>
Thank you for your help but this is not the correct solution.<br>
Your solution handles scatter plot (h2) but I want to handle a line (h1). Still do not know how to do it.<br>
Regards,<br>
Stan

Wed, 22 May 2013 23:32:31 +0000
Re: gname problem
http://www.mathworks.com/matlabcentral/newsreader/view_thread/329072#904806
dpb
On 5/18/2013 9:19 AM, Stan24 wrote:<br>
> I've forgotten to add:<br>
> gname(1:10, h1); % returns the wrong handle<br>
<br>
Don't understand what you need...gname() returns the handle of the text <br>
objects it makes; they _can't_ be "wrong" excepting you may be <br>
misunderstanding.<br>
<br>
W/ your initial call to plot(),<br>
<br>
h1 = plot(1:10, sin(1:10), 'o');<br>
<br>
gname(1:10, h1); puts up the cursor and labels the points on the line <br>
drawn theredon't know what else you want it should do???<br>
<br>
h1 is the handle to the line object returned from plot() and so using as <br>
the argument to gname will label those points.<br>
<br>
Even if I then use the second scatter() call, the h1 handle correctly <br>
identifies the line from the plot and internal logic requires being <br>
"close enough" to the points on the line that they're identified and <br>
labeled instead of the points of the scatter plot that are in the <br>
general neighborhood.<br>
<br>
Looks like working as advertised to me. What are you really after?<br>
<br>


Thu, 23 May 2013 10:42:08 +0000
Re: gname problem
http://www.mathworks.com/matlabcentral/newsreader/view_thread/329072#904850
Stan
> Don't understand what you need...gname() returns the handle of the text <br>
<br>
so try to read carefully what I wrote this will save your time and other. <br>
<br>
If the figure contains two plots: scatter and line can not handle the line. gname() handles scatter plot regardless of whether you use h1 or h2. <br>
Regards,<br>
Stan

Thu, 23 May 2013 12:19:51 +0000
Re: gname problem
http://www.mathworks.com/matlabcentral/newsreader/view_thread/329072#904861
dpb
On 5/23/2013 5:42 AM, Stan wrote:<br>
>> Don't understand what you need...gname() returns the handle of the text<br>
><br>
> so try to read carefully what I wrote this will save your time and other.<br>
> If the figure contains two plots: scatter and line can not handle the<br>
> line. gname() handles scatter plot regardless of whether you use h1 or<br>
> h2. Regards,<br>
> Stan<br>
<br>
NO. Read what I wrote carefully (and more carefully check your own work).<br>
<br>


Thu, 23 May 2013 13:01:29 +0000
Re: gname problem
http://www.mathworks.com/matlabcentral/newsreader/view_thread/329072#904864
dpb
On 5/23/2013 7:19 AM, dpb wrote:<br>
> On 5/23/2013 5:42 AM, Stan wrote:<br>
>>> Don't understand what you need...gname() returns the handle of the text<br>
>><br>
>> so try to read carefully what I wrote this will save your time and other.<br>
>> If the figure contains two plots: scatter and line can not handle the<br>
>> line. gname() handles scatter plot regardless of whether you use h1 or<br>
>> h2. Regards,<br>
>> Stan<br>
><br>
> NO. Read what I wrote carefully (and more carefully check your own work).<br>
<br>
Specifically, your example h2 is _not_ a line handle as SCATTER returns <br>
a vector of handles to the scatter objects it creates and there is no <br>
line object for it.<br>
<br>
Oh, I just see there's a problem in the doc's for SCATTER  it does say <br>
handles are line handles but that's an error. help text is correct in <br>
using scatter object.<br>
<br>
>> h1 = plot(1:10, sin(1:10), 'o');<br>
>> hold on<br>
>> h2=scatter(10*rand(1,10),2*rand(1,10)1,'x');<br>
>> get(h2,'type')<br>
ans =<br>
hggroup<br>
>> get(h1,'type')<br>
ans =<br>
line<br>
>> hch=get(h2,'children');<br>
>> for i=1:length(hch),get(hch(i),'type'),end<br>
ans =<br>
patch<br>
ans =<br>
patch<br>
ans =<br>
patch<br>
ans =<br>
patch<br>
ans =<br>
patch<br>
ans =<br>
patch<br>
ans =<br>
patch<br>
ans =<br>
patch<br>
ans =<br>
patch<br>
ans =<br>
patch<br>
<br>
>><br>
<br>
The above illustrates there is only the one line object in the figure of <br>
your example.<br>
<br>
I didn't try gname() on the scatter object handle given the description <br>
so what happens....hmmm....<br>
<br>
>> hh=gname(1:10, h2);<br>
>> hh<br>
hh =<br>
187.0046<br>
188.0046<br>
189.0046<br>
190.0046<br>
>> get(hh(1),'type')<br>
ans =<br>
text<br>
>><br>
<br>
actually works to label the patches and ignores the line handle h1.<br>
<br>
Looks like another place the doc could be updated/clarified some.<br>
<br>
OBTW, this is R2012b here...<br>
<br>
Again, looks like it functions as one would expect to me...what, again, <br>
specifically, is it that you're having a problem with or want some other <br>
behavior?<br>
<br>
