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!

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 26 Feb. 2014

2 Stimmen

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 Kommentare

mashtine
mashtine am 26 Feb. 2014
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
Azzi Abdelmalek
Azzi Abdelmalek am 26 Feb. 2014
What do you mean?
mashtine
mashtine am 26 Feb. 2014
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.
Azzi Abdelmalek
Azzi Abdelmalek am 26 Feb. 2014
I'am not following you, post a sample of your data
mashtine
mashtine am 27 Feb. 2014
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 am 27 Feb. 2014
Maybe this can help. I have my HWData as a 1x2 for testing but its is usually a 1x35
mashtine
mashtine am 27 Feb. 2014
Bearbeitet: mashtine am 27 Feb. 2014
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by