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:
remove points from a plot

Subject: remove points from a plot

From: Jonathan Lane

Date: 2 Sep, 2003 10:59:11

Message: 1 of 7

I have a picture in a figure window. Part of my program is to plot
crosses on the image after using ginput. Is it possible to remove
individual crosses from the image without having to redraw the
picture?


It would be nice, and would result in a lot less typing!


Many Thanks,


J Lane

Subject: remove points from a plot

From: rpoepa@yahoo.com (Randy Poe)

Date: 2 Sep, 2003 11:37:50

Message: 2 of 7

"Jonathan lane" <jonathanmlane@yahoo.co.uk> wrote in message news:<eec31a5.-1@WebX.raydaftYaTP>...
> I have a picture in a figure window. Part of my program is to plot
> crosses on the image after using ginput. Is it possible to remove
> individual crosses from the image without having to redraw the
> picture?

Yes. Keep track of the handles as you plot them. I gather
that each cross is a separate call to "plot", something like

    plot(x, y, '+');

Instead use this version of the call:

    h(i) = plot(x, y, '+');

where h(i) is the plot of the i-th data point. Now, if
you delete h(i), that cross will disappear.

    delete(h(i));

Because the argument to delete must be a valid handle, it's
a little safer to do it this way:

    if (ishandle(h(i))) delete(h(i)); end;

If you are not doing each point with a separate call to
plot(), but doing all points at once, it's still easy if
you store the handle.

Suppose x and y are now vectors of coordinates, and you
plotted them this way:

    plot(x, y, '+');

Again, store the handle (only one handle needed this time)

    h = plot(x, y, '+');

And if you want to delete the i-th point, delete it from
the corresponding vectors:

    x(i) = [];
    y(i) = [];
and modify the 'xdata' and 'ydata' properties of the plot with
the new versions of these vectors:
    set(h, 'xdata', x, 'ydata', y);

Handle graphics is a powerful tool in Matlab. I use the "set"
command about 10 million times a day.

            - Randy

Subject: remove points from a plot

From: us

Date: 2 Sep, 2003 14:44:58

Message: 3 of 7

Randy Poe:
<SNIP solved a plot problem elegantly>


I use the "set" command about 10 million times a day.


... wow, every 8.64 milliseconds you type a <set> - considering
you're doing much more typing between those <set>s!
doesn't come close, though, to our average student at 5.12 ms
:-)
us

Subject: remove points from a plot

From: Jonathan Lane

Date: 3 Sep, 2003 03:52:50

Message: 4 of 7

us wrote:
>
>
> Randy Poe:
> <SNIP solved a plot problem elegantly>
>
> I use the "set" command about 10 million times a day.
>
> ... wow, every 8.64 milliseconds you type a <set> -
> considering
> you're doing much more typing between those <set>s!
> doesn't come close, though, to our average student at 5.12 ms
> :-)
> us


that is indeed an impressive rate of typing.


Thanks for your help.

Subject: remove points from a plot

From: J Luis

Date: 3 Sep, 2003 09:29:38

Message: 5 of 7

Jonathan lane wrote:
>
>
> I have a picture in a figure window. Part of my program is to plot
> crosses on the image after using ginput. Is it possible to remove
> individual crosses from the image without having to redraw the
> picture?
>
> It would be nice, and would result in a lot less typing!


I understand that you would like to is remove your crosses with the
mouse.
Having the handle for each point, you can set a uicontextmenu for
each one of them
textHand = hand;
cmenu = uicontextmenu;
set(textHand, 'uicontextmenu',cmenu)
item = uimenu(cmenu,'Label',delete','Callback','delete(gco));
the problem might be if the crosses are small, for you need to catch
tem with a mouse click (right-click).

Subject: remove points from a plot

From: rpoepa@yahoo.com (Randy Poe)

Date: 3 Sep, 2003 06:58:04

Message: 6 of 7

us <us@neurol.unizh.ch> wrote in message news:<eec31a5.1@WebX.raydaftYaTP>...
> Randy Poe:
> <SNIP solved a plot problem elegantly>
>
>
> I use the "set" command about 10 million times a day.
>
>
> ... wow, every 8.64 milliseconds you type a <set> - considering
> you're doing much more typing between those <set>s!
> doesn't come close, though, to our average student at 5.12 ms

OK, slight exaggeration. Maybe 6 million.

         - Randy

Subject: remove points from a plot

From: us

Date: 3 Sep, 2003 10:00:56

Message: 7 of 7

Randy Poe wrote:
<SNIP type-rate>


> OK, slight exaggeration. Maybe 6 million.


... ok, that sounds reasonable - albeit almost pedestrian, now.
:-)
us

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