Store identical rows in specified column
이전 댓글 표시
Hi ,
I have a table that has thousands of input, an example is attached
Date ID Name Des
01/01/2021 2090260 'MIA' 'USA-MIAME'
01/01/2021 2090260 'MIA' 'USA-MIAME'
01/01/2021 2094230 'ALOC' 'USA-NEW'
01/01/2021 2094230 'ALOC' 'USA-NEW'
01/01/2021 2094700 'KATERINA' 'USA-FLORIDA'
01/01/2021 2094700 'KATERINA' 'USA-FLORIDA'
01/01/2021 2094700 'KATERINA' 'USA-FLORIDA'
01/01/2021 2094700 'KATERINA' 'USA-FLORIDA'
01/01/2021 2094700 'KATERINA' 'USA-FLORIDA'
I want to check if each input in the second column (i.e., ID) IS EQUAL. If so, store it in a seperate array or table.
so the expected output would be
Date ID Name Des
01/01/2021 2090260 'MIA' 'USA-MIAME'
01/01/2021 2090260 'MIA' 'USA-MIAME'
Date ID Name Des
01/01/2021 2094230 'ALOC' 'USA-NEW'
01/01/2021 2094230 'ALOC' 'USA-NEW'
Date ID Name Des
01/01/2021 2094700 'KATERINA' 'USA-FLORIDA'
01/01/2021 2094700 'KATERINA' 'USA-FLORIDA'
01/01/2021 2094700 'KATERINA' 'USA-FLORIDA'
01/01/2021 2094700 'KATERINA' 'USA-FLORIDA'
01/01/2021 2094700 'KATERINA' 'USA-FLORIDA'
I have written the following code but it doesnt work
clear;
% % data = Tbl.c;
[~,~,data] = xlsread('Test.csv');
Selected_Data=(data(2:end,[1 2 3 4 6 9 10 18 ]));
% Remove NAN rows
Selected_Data(any(cellfun(@(x) any(isnan(x)),Selected_Data),2),:) = [];
Selected_Data1 = cell2table(Selected_Data);
Selected_Data2=sortrows(Selected_Data1,{'Selected_Data2'},{'ascend'});
Selected_Data2.Properties.VariableNames = {'TimeStamp' 'MMSI' 'LATITUDE' 'LONGITUDE' 'SPEED' 'IMO' 'NAME' 'DES'};
% this part doesnt work
for i= 1:size(Selected_Data2,1)
for iter=1:size(Selected_Data2,1) %Selected_Data2 is the table name
if Selected_Data2(iter,2)=Selected_Data2(iter+1,2) % check condition
Segments=Selected_Data2(iter,:); % Store identical ID with all relevant data in a table or cell array
end
end
Group_Segment(i)=Segments;
end
댓글 수: 3
Scott MacKenzie
2022년 3월 12일
편집: Scott MacKenzie
2022년 3월 12일
No data file was attached.
neamah al-naffakh
2022년 3월 12일
Scott MacKenzie
2022년 3월 12일
OK, thanks. I just posted an answer.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Point Cloud Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!