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:
Help to find sign change points in a vector

Subject: Help to find sign change points in a vector

From: Dips Bhatia

Date: 21 Oct, 2009 21:52:17

Message: 1 of 4

Hi,
Am new to Matlab and I needed help to analyse a some data and find the points at which the data crosses the 0. Can someone help me with this.

Subject: Help to find sign change points in a vector

From: Nasser M. Abbasi

Date: 22 Oct, 2009 00:28:24

Message: 2 of 4


"Dips Bhatia" <deepakdbhatia@gmail.com> wrote in message
news:hbnvqh$11a$1@fred.mathworks.com...
> Hi,
> Am new to Matlab and I needed help to analyse a some data and find the
> points at which the data crosses the 0. Can someone help me with this.

This is one way I think you can do the above. I am sure there are other ways

Take you vector data, make all the points which are positive to be 1, and
all which is negative to be 0.

Then apply diff() on the result.

Look at the result, anywhere it is not zero, then this is a sign change
position in the orginal vector.

Here is an example

=[1 2 -3 7 8 -1 -2 -3 9 1 2 3 -1];
A(A>1)=1;
A(A<1)=0;
find(diff(A)~=0)

ans =

     2 3 5 8 12

--Nasser

Subject: Help to find sign change points in a vector

From: NZTideMan

Date: 22 Oct, 2009 02:25:04

Message: 3 of 4

On Oct 22, 1:28 pm, "Nasser M. Abbasi" <n...@12000.org> wrote:
> "Dips Bhatia" <deepakdbha...@gmail.com> wrote in message
>
> news:hbnvqh$11a$1@fred.mathworks.com...
>
> > Hi,
> > Am new to Matlab and I needed help to analyse a some data and find the
> > points at which the data crosses the 0. Can someone help me with this.
>
> This is one way I think you can do the above. I am sure there are other ways
>
> Take you vector data, make all the points which are positive to be 1, and
> all which is negative to be 0.
>
> Then apply diff() on the result.
>
> Look at the result, anywhere it is not zero, then this is a sign change
> position in the orginal vector.
>
> Here is an example
>
> =[1 2 -3 7 8 -1 -2 -3 9 1 2 3 -1];
> A(A>1)=1;
> A(A<1)=0;
> find(diff(A)~=0)
>
> ans =
>
>      2     3     5     8    12
>
> --Nasser

And here's another way:

A=[1 2 -3 7 8 -1 -2 -3 9 1 2 3 -1];
find(A(1:end-1).*A(2:end)<0)
     2 3 5 8 12

Subject: Help to find sign change points in a vector

From: Dips Bhatia

Date: 22 Oct, 2009 07:16:18

Message: 4 of 4

Hi thank you very much for both your replies. Was very helpful. I tried on my own and had ended by with for loop and if statements but was sure there is a more elegant way to do it.



NZTideMan <mulgor@gmail.com> wrote in message <b64067ed-2bc7-4bde-a1d9-97807ea0e9e9@m33g2000pri.googlegroups.com>...
> On Oct 22, 1:28?pm, "Nasser M. Abbasi" <n...@12000.org> wrote:
> > "Dips Bhatia" <deepakdbha...@gmail.com> wrote in message
> >
> > news:hbnvqh$11a$1@fred.mathworks.com...
> >
> > > Hi,
> > > Am new to Matlab and I needed help to analyse a some data and find the
> > > points at which the data crosses the 0. Can someone help me with this.
> >
> > This is one way I think you can do the above. I am sure there are other ways
> >
> > Take you vector data, make all the points which are positive to be 1, and
> > all which is negative to be 0.
> >
> > Then apply diff() on the result.
> >
> > Look at the result, anywhere it is not zero, then this is a sign change
> > position in the orginal vector.
> >
> > Here is an example
> >
> > =[1 2 -3 7 8 -1 -2 -3 9 1 2 3 -1];
> > A(A>1)=1;
> > A(A<1)=0;
> > find(diff(A)~=0)
> >
> > ans =
> >
> > ? ? ?2 ? ? 3 ? ? 5 ? ? 8 ? ?12
> >
> > --Nasser
>
> And here's another way:
>
> A=[1 2 -3 7 8 -1 -2 -3 9 1 2 3 -1];
> find(A(1:end-1).*A(2:end)<0)
> 2 3 5 8 12

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