Find set of values that are unique to the values in first two columns in a table

조회 수: 23 (최근 30일)
I have a table like the following. Columns C1, C2, and C3. Based on the unique values on first two columns, I need to collect all the values in a vector. In the below table, I have 7 unique rows. For each unique row, lets say [3,1], i need to collect values from column C3 as a vector [2,5] etc. Also please note that the first column C1 is a categorical data. eg, date. Any help is appreciated. Thanks
C1 C2 C3
3 1 2
3 1 5
3 3 1
1 3 3
3 2 3
2 3 3
1 1 3
1 2 3
2 3 2
3 3 2
3 3 8
3 3 1
1 3 10
  댓글 수: 1
the cyclist
the cyclist 2019년 11월 24일
It would be easier to help if you uploaded the actual table (or a representative sample) in a *.mat file. This will prevent us from having to guess at exactly how your data are stored, what the date type is, etc.

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

채택된 답변

Ridwan Alam
Ridwan Alam 2019년 11월 24일
편집: Ridwan Alam 2019년 11월 24일
I believe what you are looking for is the unique() function, specially the z in the example below:
>> mytable
mytable =
5×3 table
Var1 Var2 Var3
___________ ____ ____
20-Nov-2019 92 57
21-Nov-2019 29 8
22-Nov-2019 76 6
22-Nov-2019 76 54
24-Nov-2019 39 78
>> [x,y,z]=unique(mytable(:,1:2))
x =
4×2 table
Var1 Var2
___________ ____
20-Nov-2019 92
21-Nov-2019 29
22-Nov-2019 76
24-Nov-2019 39
y =
1
2
3
5
z =
1
2
3
3
4
Using "z" you can sort out your third column values. One way to do:
newVar = {};
for i = 1:max(z)
newVar{i} = table2array(mytable(z==i,3))';
end
Please let me know how it goes.
  댓글 수: 1
dpb
dpb 2019년 11월 24일
If going to use unique, use the 'rows' optional argument here.
Alternatively, look at findgroups

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by