Info

This question is closed. Reopen it to edit or answer.

Looping the column elements of the Matrix

1 view (last 30 days)
Najam us Saqib Fraz
Najam us Saqib Fraz on 9 Oct 2020
Closed: MATLAB Answer Bot on 20 Aug 2021
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)

Answers (1)

Matt J
Matt J on 9 Oct 2020
Edited: Matt J on 9 Oct 2020
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 Comments

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by