Extract duplicate values from both 1st and 2nd column
Afficher commentaires plus anciens
I have a large matrix (120000x4096)to process. There are repetitions in the 1st and 2nd columns. If 2 rows have the same number in the 1st and the 2nd column, only one row is stored. However, if 2 rows have the same number in the 1st columns but different numbers in the 2nd one, both rows are stored. Then extract the other columns related to each set of rows. This can seen in the attached file
Any ideas to do it without a loop please?
Thanks for your help!
Réponse acceptée
Plus de réponses (1)
Thomas Koelen
le 9 Avr 2015
Modifié(e) : Thomas Koelen
le 9 Avr 2015
a=[10 10 10; 10 10 10; 5 5 5; 4 4 4];
a =
10 10 10
10 10 10
5 5 5
4 4 4
Code:
a=[10 10 10; 10 10 10; 5 5 5; 4 4 4; 4 4 4];
sizea=size(a);
for i=1:sizea(1,1)
for i2=1:sizea(1,2)
sizea=size(a);
if a(i,i2)==a(i+1,i2)
a(i+1,:)=[];
if i==sizea(1,1)-1
return
end
end
end
end
a =
10 10 10
5 5 5
4 4 4
Where a is your scan matrix!
1 commentaire
Thomas Koelen
le 9 Avr 2015
Made the code a bit nicer since it was hard to read.
Catégories
En savoir plus sur Language Support dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!