Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
gname problem

Subject: gname problem

From: Stan24

Date: 18 May, 2013 13:22:10

Message: 1 of 8

Hi,
Can anyone explain how to add case names to plot:

h1 = plot(1:10, sin(1:10), 'o-');
hold on;
h2 = gscatter(10*rand(1, 10), 2*rand(1,10), 1:10);
hold off;

gname(1:10, h1);

Thanks,
Stan

Subject: gname problem

From: Stan24

Date: 18 May, 2013 14:19:10

Message: 2 of 8

I've forgotten to add:
gname(1:10, h1); % returns the wrong handle

Subject: gname problem

From: Tom Lane

Date: 22 May, 2013 20:53:01

Message: 3 of 8

> I've forgotten to add:
> gname(1:10, h1); % returns the wrong handle

I just tried this. If I type

   hh = gname(1:10, h1);

and then I click points on the plot, only point with handles in h1 get
labeled. The return value hh is a vector of handles to the text labels. So
for example,

   set(hh,'color','m')

turns the text magenta. This appears to be working correctly. What do you
see that seems wrong?

-- Tom

Subject: gname problem

From: Stan

Date: 22 May, 2013 22:08:09

Message: 4 of 8

Hi Tom,
Thank you for your help but this is not the correct solution.
Your solution handles scatter plot (h2) but I want to handle a line (h1). Still do not know how to do it.
Regards,
Stan

Subject: gname problem

From: dpb

Date: 22 May, 2013 23:32:31

Message: 5 of 8

On 5/18/2013 9:19 AM, Stan24 wrote:
> I've forgotten to add:
> gname(1:10, h1); % returns the wrong handle

Don't understand what you need...gname() returns the handle of the text
objects it makes; they _can't_ be "wrong" excepting you may be
misunderstanding.

W/ your initial call to plot(),

h1 = plot(1:10, sin(1:10), 'o-');

gname(1:10, h1); puts up the cursor and labels the points on the line
drawn there--don't know what else you want it should do???

h1 is the handle to the line object returned from plot() and so using as
the argument to gname will label those points.

Even if I then use the second scatter() call, the h1 handle correctly
identifies the line from the plot and internal logic requires being
"close enough" to the points on the line that they're identified and
labeled instead of the points of the scatter plot that are in the
general neighborhood.

Looks like working as advertised to me. What are you really after?

--

Subject: gname problem

From: Stan

Date: 23 May, 2013 10:42:08

Message: 6 of 8

> Don't understand what you need...gname() returns the handle of the text

so try to read carefully what I wrote this will save your time and other.

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.
Regards,
Stan

Subject: gname problem

From: dpb

Date: 23 May, 2013 12:19:51

Message: 7 of 8

On 5/23/2013 5:42 AM, Stan wrote:
>> Don't understand what you need...gname() returns the handle of the text
>
> so try to read carefully what I wrote this will save your time and other.
> 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. Regards,
> Stan

NO. Read what I wrote carefully (and more carefully check your own work).

--

Subject: gname problem

From: dpb

Date: 23 May, 2013 13:01:29

Message: 8 of 8

On 5/23/2013 7:19 AM, dpb wrote:
> On 5/23/2013 5:42 AM, Stan wrote:
>>> Don't understand what you need...gname() returns the handle of the text
>>
>> so try to read carefully what I wrote this will save your time and other.
>> 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. Regards,
>> Stan
>
> NO. Read what I wrote carefully (and more carefully check your own work).

Specifically, your example h2 is _not_ a line handle as SCATTER returns
a vector of handles to the scatter objects it creates and there is no
line object for it.

Oh, I just see there's a problem in the doc's for SCATTER -- it does say
handles are line handles but that's an error. help text is correct in
using scatter object.

 >> h1 = plot(1:10, sin(1:10), 'o-');
 >> hold on
 >> h2=scatter(10*rand(1,10),2*rand(1,10)-1,'x');
 >> get(h2,'type')
ans =
hggroup
 >> get(h1,'type')
ans =
line
 >> hch=get(h2,'children');
 >> for i=1:length(hch),get(hch(i),'type'),end
ans =
patch
ans =
patch
ans =
patch
ans =
patch
ans =
patch
ans =
patch
ans =
patch
ans =
patch
ans =
patch
ans =
patch

 >>

The above illustrates there is only the one line object in the figure of
your example.

I didn't try gname() on the scatter object handle given the description
so what happens....hmmm....

 >> hh=gname(1:10, h2);
 >> hh
hh =
   187.0046
   188.0046
   189.0046
   190.0046
 >> get(hh(1),'type')
ans =
text
 >>

actually works to label the patches and ignores the line handle h1.

Looks like another place the doc could be updated/clarified some.

OBTW, this is R2012b here...

Again, looks like it functions as one would expect to me...what, again,
specifically, is it that you're having a problem with or want some other
behavior?

--

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us