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:
How to get vector indices in a plot by clicking?

Subject: How to get vector indices in a plot by clicking?

From: Aquiles Carattino

Date: 16 Sep, 2010 19:43:06

Message: 1 of 6

Hi all!
I'm currently plotting some data, and I need to be able to choose a part of it for fitting afterwards.
I tried with ginput but it stores the clicking coordinates and I would need to know the index of the vector of the data I clicked. So I can just do something like

newvector=oldvector(start:end);

Is it possible?

Thanks!

Subject: How to get vector indices in a plot by clicking?

From: Sean

Date: 16 Sep, 2010 20:04:23

Message: 2 of 6

"Aquiles Carattino" <spam@aquic.com.ar> wrote in message <i6ts0a$54u$1@fred.mathworks.com>...
> Hi all!
> I'm currently plotting some data, and I need to be able to choose a part of it for fitting afterwards.
> I tried with ginput but it stores the clicking coordinates and I would need to know the index of the vector of the data I clicked. So I can just do something like
>
> newvector=oldvector(start:end);
>
> Is it possible?
>
> Thanks!

So how about :
pts = ginput(2); %get two end points, we're going to use the x-axis for this example

Then use the results of that to determine what part of the vector you'll need, i.e.:
newvector = oldvector(oldvector>min(pts(3:4))&old_vector<max(pts(3:4)));

Subject: How to get vector indices in a plot by clicking?

From: Aquiles Carattino

Date: 16 Sep, 2010 20:17:21

Message: 3 of 6

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i6tt87$nte$1@fred.mathworks.com>...
> "Aquiles Carattino" <spam@aquic.com.ar> wrote in message <i6ts0a$54u$1@fred.mathworks.com>...
> > Hi all!
> > I'm currently plotting some data, and I need to be able to choose a part of it for fitting afterwards.
> > I tried with ginput but it stores the clicking coordinates and I would need to know the index of the vector of the data I clicked. So I can just do something like
> >
> > newvector=oldvector(start:end);
> >
> > Is it possible?
> >
> > Thanks!
>
> So how about :
> pts = ginput(2); %get two end points, we're going to use the x-axis for this example
>
> Then use the results of that to determine what part of the vector you'll need, i.e.:
> newvector = oldvector(oldvector>min(pts(3:4))&old_vector<max(pts(3:4)));

It was so simple...

Subject: How to get vector indices in a plot by clicking?

From: Aquiles Carattino

Date: 16 Sep, 2010 20:53:05

Message: 4 of 6

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i6tt87$nte$1@fred.mathworks.com>...
> "Aquiles Carattino" <spam@aquic.com.ar> wrote in message <i6ts0a$54u$1@fred.mathworks.com>...
> > Hi all!
> > I'm currently plotting some data, and I need to be able to choose a part of it for fitting afterwards.
> > I tried with ginput but it stores the clicking coordinates and I would need to know the index of the vector of the data I clicked. So I can just do something like
> >
> > newvector=oldvector(start:end);
> >
> > Is it possible?
> >
> > Thanks!
>
> So how about :
> pts = ginput(2); %get two end points, we're going to use the x-axis for this example
>
> Then use the results of that to determine what part of the vector you'll need, i.e.:
> newvector = oldvector(oldvector>min(pts(3:4))&old_vector<max(pts(3:4)));

But, there's a problem... What if the vector repeats values, say, like a gaussian, and you just want to select one of the sides from the maximum...

Subject: How to get vector indices in a plot by clicking?

From: Sean

Date: 16 Sep, 2010 22:17:05

Message: 5 of 6

"Aquiles Carattino" <spam@aquic.com.ar> wrote in message ]
> But, there's a problem... What if the vector repeats values, say, like a gaussian, and you just want to select one of the sides from the maximum...

Then use the same logic with the y-coordinates returned from ginput() and the dependent vector being plotted.

Subject: How to get vector indices in a plot by clicking?

From: Alan B

Date: 16 Sep, 2010 22:45:20

Message: 6 of 6

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i6u510$i2u$1@fred.mathworks.com>...
> "Aquiles Carattino" <spam@aquic.com.ar> wrote in message ]
> > But, there's a problem... What if the vector repeats values, say, like a gaussian, and you just want to select one of the sides from the maximum...
>
> Then use the same logic with the y-coordinates returned from ginput() and the dependent vector being plotted.

Using the data cursor is a simpler solution. You can use that to export the cursor data to the workspace, or you can write your own callback that saves it to a file or whatever you need.

Tags for 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