From: Natalie Sin Hwee on
Hello there^^

Matrix A contains randomly of 1's and 0's in a size 1000-by-100 matrix .
for each column, i'd like to find the elements containting 1 by applying 'find'.

I've tried:
===
A=rand(1000,1000)
for n=1:a % 1:a
c=find(A(:,1));
% first=[r,c];
end
===
and basically returns me the elements containing '1' in column 1
e.g.
3
6
23
29
48
....
999


** I now want to apply across all columns i.e. 1:1000. How can do this?
I've tried the code below, but that only returns me the result of the last column and places it in column 1.

A=rand(1000,1000)
for n=1:a % 1:a
c=find(A(:,n));
% first=[r,c];
end

==
but i want something like below:


3 4 1 5 ...... etc
5 42 17 22
8 57 23 55
23 etc. etc. etc.
27
56
58
60
89
99


basically a 1000 column matrix, but the row lengths differ. (if possible?)

Thanks ^^

Natalie !!
From: Bruno Luong on
"Natalie Sin Hwee " <sin.ng09(a)imperial.ac.uk> wrote in message <hoshcj$bkj$1(a)fred.mathworks.com>...
> Hello there^^
>
> Matrix A contains randomly of 1's and 0's in a size 1000-by-100 matrix .
> for each column, i'd like to find the elements containting 1 by applying 'find'.

% Data
A=rand(10)>0.7

% Engine
[R C] = find(A)
R = accumarray(C(:), R(:), [size(A,2) 1], @(r) {r});

R{:}

% Bruno