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

18 次查看(过去 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.

更多回答(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