I need to separate same first column data values and its corresponding second column value.

2 次查看(过去 30 天)
I have two dimensional data, as shown in figure.
I need to separate same first coloumn (column 1) data values and its corresponding second column (column 2) value, into groups.
How can I do this ?
Thanks in advance.
  2 个评论
the cyclist
the cyclist 2021-5-18
编辑:the cyclist 2021-5-18
When you say "separated", what specifically do you mean? How do you want the output organized?
Do you still need just one table, but with the values sorted? Or one table, but with an additional variable to define the unique values in column1? Or maybe you need a new table for every value in the first column?
zhoug zho
zhoug zho 2021-5-18
I still need two columns, basically I need to separate all the first column elements that are similar.
And then, as elements of first column are exactly same, so I will consider it one value, but their corresponding values in column 2 will be added and average out of all these similar ,
So in this case, I have one values from column 1 and its corresponding column 2 averaged value.

请先登录,再进行评论。

采纳的回答

Adam Danz
Adam Danz 2021-5-18
编辑:Adam Danz 2021-5-18
Another method using groupsummary
% Create demo table
g = repelem((1:2:9)',randi(4,5,1)+1,1);
T = table(g, rand(numel(g),1).*randi([2,8],numel(g),1), ...
'VariableNames', {'column1','column2'})
T = 16×2 table
column1 column2 _______ ________ 1 5.7244 1 1.6392 1 1.7206 1 0.64037 3 0.073685 3 1.9413 3 1.6698 5 1.3814 5 1.4611 7 1.0805 7 1.1879 7 0.42207 7 1.3179 9 4.5171 9 0.38479 9 2.9267
% Average column 2 for each group in column 1
Tstats = groupsummary(T,'column1','mean','column2')
Tstats = 5×3 table
column1 GroupCount mean_column2 _______ __________ ____________ 1 4 2.4311 3 3 1.2283 5 2 1.4212 7 4 1.0021 9 3 2.6095

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by