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

3 Ansichten (letzte 30 Tage)
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 Kommentare
the cyclist
the cyclist am 18 Mai 2021
Bearbeitet: the cyclist am 18 Mai 2021
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 am 18 Mai 2021
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Adam Danz
Adam Danz am 18 Mai 2021
Bearbeitet: Adam Danz am 18 Mai 2021
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

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by