필터 지우기
필터 지우기

Find unique column values in NxN cell array

조회 수: 1 (최근 30일)
tybo1mos
tybo1mos 2022년 12월 2일
답변: Paul 2022년 12월 2일
I have a 1000x50 cell array with each column contining multiple duplicate entries.
simplified example:
names = {'red','blue','green';'red','orange','yellow';'orange','orange','red'};
{'red' } {'blue' } {'green' }
{'red' } {'orange'} {'yellow'}
{'orange'} {'orange'} {'red' }
I would to create a simplified array wich contains only the unique values from each of the indiviual columns:
result:
{'red' } {'blue' } {'green' }
{'orange'} {'orange'} {'yellow'}
{'red' }
  댓글 수: 2
tybo1mos
tybo1mos 2022년 12월 2일
My original data is actually in table form. So my prference would be to work from the original table data, and rutun a table with only unique values.
Starting:
color_1 color_2 color_3
________ ________ ________
'red' 'blue' 'green'
'red' 'orange' 'yellow'
'orange' 'orange' 'red'
Reult
color_1 color_2 color_3
_______ ________ ________
'red' 'blue' 'green'
'orange' 'orange' 'yellow'
'red'
Paul
Paul 2022년 12월 2일
Is that result feasible? I thought each table variable has to have the same number of rows?

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

답변 (1개)

Paul
Paul 2022년 12월 2일
Because the resulting variables could all have a different number of elements, I'm converting each variable into a scalar cell that contains the desired data
t = table({'red';'red';'orange'},{'blue';'orange';'orange'},{'green';'yellow';'red'})
t = 3×3 table
Var1 Var2 Var3 __________ __________ __________ {'red' } {'blue' } {'green' } {'red' } {'orange'} {'yellow'} {'orange'} {'orange'} {'red' }
t = varfun(@(x){unique(x,'stable')},t)
t = 1×3 table
Fun_Var1 Fun_Var2 Fun_Var3 __________ __________ __________ {2×1 cell} {2×1 cell} {3×1 cell}
t.(1){:}
ans = 2×1 cell array
{'red' } {'orange'}
t.(2){:}
ans = 2×1 cell array
{'blue' } {'orange'}
t.(3){:}
ans = 3×1 cell array
{'green' } {'yellow'} {'red' }

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by