Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Finding first nonzeros immediately following zeros in a matrix
Replies: 1   Last Post: Jan 30, 2013 8:20 PM

 Derek Goring Posts: 3,922 Registered: 12/7/04
Re: Finding first nonzeros immediately following zeros in a matrix
Posted: Jan 30, 2013 8:20 PM

On Thursday, January 31, 2013 1:17:23 PM UTC+13, Justin wrote:
> Hey everyone,
>
>
>
> I have a matrix that is one column made up of 3,700 rows. The column is only filled with zeros and ones
>
>
>
> I need a function that will grab the first ones that follow right behind the zeros in the column.
>
>
>
> Ex)
>
>
>
> A=[0;0;1;1;1;1;0;0;0;0;1;1;1;0;1;0;0;0;0;1;1;0;1]
>
>
>
> I would want the ones immediately following the zeros in the matrix.
>
>
>
> In this case I would want the 3rd, 11th, 15th, 20th, and 23rd numbers.
>
>
>
> Thank you.

dA=diff(A);
indx=find(dA>0) + 1