Info

此问题已关闭。 请重新打开它进行编辑或回答。

Looping the column elements of the Matrix

1 次查看(过去 30 天)
Hello Every one !!! Following data is a small part of large data.I want to write a program that can go to first coloumn,and for all first elements that are 527.12347,it procedes to third coloumn.In third coloumn,it should select the minimum values ( please keep in mind it is the minimum value for which the value of first coloumn is 527.12347),and should average the coresponding values in 4th coloumn.
Than it procedes to next value in first coloumn i.e the value after 527.12347 is 532.12347.There again it goes to third coloumn.For minimum values in third coloumn it should average corresponding values in 4h coloumn.Simply putting output showed look like this
527.12347 ( average value of 4th coloumn corresponding to minimum values in third coloumn for 527.12347)
532.12347 ( average value of 4th coloumn corresponding to minimum values in third coloumn for 532.12347)
537.1892 ( average value of 4th coloumn corresponding to minimum values in third coloumn for 537.1892)
542.6397 ( average value of 4th coloumn corresponding to minimum values in third coloumn for 542.6397)

回答(1 个)

Matt J
Matt J 2020-10-9
编辑:Matt J 2020-10-9
data=(randi(3,10,4)); %artificial data example
[G,ID]=findgroups(data(:,1));
Means=splitapply(@(a,b) mean(b(a==min(a))), data(:,3), data(:,4) ,G );
result=[ID,Means];
data, result
data = 10×4
2 3 1 1 2 1 2 3 3 3 2 2 1 1 3 3 1 3 3 3 1 2 1 2 3 1 2 1 3 1 3 2 1 3 2 2 1 2 3 2
result = 3×2
1.0000 2.0000 2.0000 1.0000 3.0000 1.5000
  2 个评论
Najam us Saqib Fraz
Najam us Saqib Fraz 2020-10-10
is findgroups latest command ? Because I am using the 2015a !! and it says undefined function of findgroups

标签

Community Treasure Hunt

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

Start Hunting!

Translated by