find repeated columns of a matrix

13 views (last 30 days)
Hello,
Consider a 8x100 matrix.
It consists of 5 8x1 columns that are repeated randomly, namely the col1,...,col5.
How can I find the indexes of the columns that contain the col1?
Thank you.
Pavlos

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 1 Nov 2012
A=repmat(rand(8,5),1,100/5)
A=A(:,randperm(100)) % your matrix
col1=A(:,1)
idx=find(~any(bsxfun(@minus, A,col1)))

More Answers (1)

Matt J
Matt J on 1 Nov 2012
Edited: Matt J on 1 Nov 2012
indices=find(ismember(yourmatrix.',col1.','rows'))
  4 Comments
Matt J
Matt J on 1 Nov 2012
Hah! I hit 500 points because of your upvote. Thanks!
pavlos
pavlos on 2 Nov 2012
thanks for your help

Sign in to comment.

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!