Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Derek Goring

Posts: 3,919
Registered: 12/7/04
Re: Finding first nonzeros immediately following zeros in a matrix
Posted: Jan 30, 2013 8:20 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.