Delete duplicate rows from large cell array

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일

2 개 추천

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월 26일
Hey, Thanks for the reply!
I am having some trouble working this with my cell array. If I were to look only at my time array, that is HWData{1,1}{1,1} and I am not too sure how to implement that with your code nor star's own.
Thanks for the patience haha
What do you mean?
mashtine
mashtine 2014년 2월 26일
You used A in your example so if A was structured like my cell array it would a 1 x 35 with 1 x 8 arrays where A{1,1}{1,1} would be the array containing the time data (2000-01 ...). I do not know how to implement that with your code.
I'am not following you, post a sample of your data
mashtine
mashtine 2014년 2월 27일
I do not have access to it right now but if I could try and explain again (bare with me sorry) the time col is within a 1 x 8 cell array. So because my matlab lingo is not the best in simple terms, when I double click on my file from the workspace, I see a row that contains 35 1x8 cell arrays and when I click on the first cell array, I get a row with 8 more cell arrays (the cols of data I showed above and each has about a mil rows of data and 1 col, eg: the time column)
mashtine
mashtine 2014년 2월 27일
Maybe this can help. I have my HWData as a 1x2 for testing but its is usually a 1x35
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.
strjoin requires MATLAB R2014a or above

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

질문:

2014년 2월 26일

댓글:

2014년 8월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by