Quantcast
Viewing all articles
Browse latest Browse all 55

Re: Finding when x appears in every column

On 08/21/2015 1:58 PM, someone wrote:
> "rebecca girton" wrote in message
> <mr7csr$eu8$1@newscl01ah.mathworks.com>...
>> I am trying to find the first time 0 appears in every column. My
>> matrix is 1000x100 random numbers. So I am trying to find the position
>> of the first '0' in each of the 100 columns. Can anyone help?
>
> Do you mean you have a matrix of random INTEGERS? Otherwise, I'm not
> sure what you mean by position of first '0' in the column.
>
> If they are integers, then:
>
> [row,col] = find(~X);
>
> will return the row and column subscripts of each zero element in array
> X. From there, I'll leave it to you to find the first row position in
> each of the 100 columns (if any).

Had reason to do something like this not too long ago; thought the
following was kinda' cute... :)

Given the above output from FIND()

ix=[1; diff(col)]~=0;
rowcol=[row(ix) col(ix)];

Amazingly enough at first blush, the above works whether there's a 0 in
every column or not...

--

Viewing all articles
Browse latest Browse all 55

Trending Articles