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

조회 수: 3 (최근 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에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by