Removing rows with identical values in four columns.

1 回表示 (過去 30 日間)
Miguel L
Miguel L 2015 年 12 月 27 日
コメント済み: Miguel L 2015 年 12 月 27 日
Hello. I have a large matrix with dimensions of 300123 x 8.
As a note, I would like to say that in the matrix, column 1 to column 4 are time data (year, month, day, hour), and column 5 to column 8 are meteorological data measurements.
I want to delete all rows which have the same elements in column 1, column 2, column 3 and column 4.
For instance: a = [2009,10,9,5,0,0,0,0; 2009,10,2,5,3,8,7,7; 2009,10,9,5,2,1,9,1] => [2009,10,2,5,3,8,7,7]
In this example, column 1 to column 4 has repeated values in row 1 and row 3 (2009,10,9,5), and both rows are completely removed.
I want to implement this kind of solution to my whole matrix with dimensions of 300123 x 8.
Thanks in advance.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 12 月 27 日
編集済み: Azzi Abdelmalek 2015 年 12 月 27 日
a = [2009,10,9,5,0,0,0,0
2009,10,2,5,3,8,7,7
2009,10,9,5,2,1,9,1
2004,10,9,5,2,1,9,1
2004,10,9,5,2,1,9,1
2004,10,9,5,2,1,9,1
2004,10,9,5,2,1,9,1
2024,10,9,5,2,1,9,1]
[ii,jj,kk]=unique(a(:,1:4),'rows','stable');
uu=accumarray(kk,1);
w=logical(zeros(numel(kk),1))
for k=1:numel(uu)
if uu(k)>1
w=w | (kk==k);
end
end
a(w,:)=[]
  1 件のコメント
Miguel L
Miguel L 2015 年 12 月 27 日
It works.
Thanks Azzi.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by