Delete duplicate rows from large cell array

1 回表示 (過去 30 日間)
mashtine
mashtine 2014 年 2 月 26 日
I have a cell array of the structure 1 x 35 then 1 x 8. This hold data for 35 years and the 8 columns of the 1 x 8 array hold data in various formats eg:
'2000-01-10 1:00' 'HCM' '268' '20' '260' '2345' '0' '90'
However, the data has come with duplicates like this:
'2000-01-10 1:00' 'HCM' '268' '20' '260' '2345' '0' '90'
'2000-01-10 1:00' 'HCM' '268' '20' '260' '2345' '0' '90'
'2000-01-10 2:00' 'HCM' '268' '14' '210' '645' '3' '12'
'2000-01-10 2:00' 'HCM' '268' '14' '210' '645' '3' '12'
'2000-01-10 3:00' 'HCM' '268' '02' '230' '345' '2' '40'
'2000-01-10 3:00' 'HCM' '268' '02' '230' '345' '2' '40'
As chronological order is very important, I would like to remove corresponding duplicate rows (based on the first time col, if my file was name X, the time col would be X{1,1}{1,1}) from each array without changing the order to get something like this:
'2000-01-10 1:00' 'HCM' '268' '20' '260' '2345' '0' '90'
'2000-01-10 2:00' 'HCM' '268' '14' '210' '645' '3' '12'
'2000-01-10 3:00' 'HCM' '268' '02' '230' '345' '2' '40'
Big help if you can help me. I have tried many too may options!

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 2 月 26 日
A={'2000-01-10 1:00' 'HCM' '268' '20' '260' '2345' '0' '90'
'2000-01-10 1:00' 'HCM' '268' '20' '260' '2345' '0' '90'
'2000-01-10 2:00' 'HCM' '268' '14' '210' '645' '3' '12'
'2000-01-10 2:00' 'HCM' '268' '14' '210' '645' '3' '12'
'2000-01-10 3:00' 'HCM' '268' '02' '230' '345' '2' '40'
'2000-01-10 3:00' 'HCM' '268' '02' '230' '345' '2' '40'}
[ii,jj]=unique(arrayfun(@(x) strjoin(A(x,:)),(1:size(A,1))','un',0))
out=A(jj,:)
  8 件のコメント
mashtine
mashtine 2014 年 2 月 27 日
編集済み: mashtine 2014 年 2 月 27 日
I am also getting this error with the code:
??? Undefined function or method 'strjoin' for input arguments of type 'cell'.
Error in ==> @(x)strjoin(A{x,:})
Perhaps my version is too old. Even when I try your code, matlab is giving me a strjoin error.
Aurelien Queffurust
Aurelien Queffurust 2014 年 8 月 29 日
strjoin requires MATLAB R2014a or above

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by