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:
putting 'find' results into its respective columns

Subject: putting 'find' results into its respective columns

From: Natalie Sin Hwee

Date: 30 Mar, 2010 09:48:03

Message: 1 of 2

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 !!

Subject: putting 'find' results into its respective columns

From: Bruno Luong

Date: 30 Mar, 2010 11:17:07

Message: 2 of 2

"Natalie Sin Hwee " <sin.ng09@imperial.ac.uk> wrote in message <hoshcj$bkj$1@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

Tags for 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