필터 지우기
필터 지우기

How to take last entry of each unique name

조회 수: 3 (최근 30일)
Mekala balaji
Mekala balaji 2018년 5월 6일
편집: Stephen23 2018년 6월 10일
Hi,
I have below cell array,
2018-1-2 MDS09FG HTF03K00E4T00 TF0224.1 34 43
2018-1-2 MDS09FG HTF03K00E4T00 TF0224.1 54 2
2018-1-2 MDS09FG HTF03K00E4T00 VF0224.1 64 2.6
2018-1-2 UDS09FG HTF06K00E4T00 TF0674.1 3 36
2018-1-2 UDS09FG HTF06K00E4T00 TF0674.1 54 4.3
2018-1-2 UDS09FG HTF06K00E4T00 TF0674.1 64 2.9
2018-1-2 UDS09FG HTF06K00E4T00 TF0674.1 64 2.9
2018-4-23 GJS09FG HTF06K00E4T00 TF0864.1 3 41
2018-4-23 GJS09FG HTF06K00E4T00 TF0864.1 54 1.3
2018-4-23 GJS09FG HTF06K00E4T00 TF0864.1 64 29
Based on 4th column, for each unique name in 4th column, there will be 3 to 4 rows with the same name in 4th column, I want to take the last entry(row) for each unique name in 4th column. Desired output:
2018-1-2 MDS09FG HTF03K00E4T00 VF0224.1 64 2.6
2018-1-2 UDS09FG HTF06K00E4T00 TF0674.1 64 2.9
2018-4-23 GJS09FG HTF06K00E4T00 TF0864.1 64 29
  댓글 수: 4
Stephen23
Stephen23 2018년 5월 7일
편집: Stephen23 2018년 5월 7일
Your example output shows rows. When I check the cell array I found four unique names in the fourth column:
>> unique(C(:,4))
ans =
TF0224.1
TF0674.1
TF0864.1
VF0224.1
What is the correct required output?
Mekala balaji
Mekala balaji 2018년 6월 10일
편집: Stephen23 2018년 6월 10일
Sir,
I encounter an issue, my out does not maintain original order, in fact, I want to retain the original row order.
Can it be possible to retain the original order. I legacy, but still I get wrong ordre:
ia =
1
3
8
11
[C,ia,ic] = unique(input(:,4),'rows','legacy')

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

채택된 답변

Fangjun Jiang
Fangjun Jiang 2018년 5월 7일
use [out, IA]=unique(in,'last'), assume your 2D cell array is in,
[out,IA]=unique(in(:,4),'last')
out=in(IA,:)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by