Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Looping the column elements of the Matrix

1 visualizzazione (ultimi 30 giorni)
Najam us Saqib Fraz
Najam us Saqib Fraz il 9 Ott 2020
Chiuso: MATLAB Answer Bot il 20 Ago 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)

Risposte (1)

Matt J
Matt J il 9 Ott 2020
Modificato: Matt J il 9 Ott 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 Commenti
Najam us Saqib Fraz
Najam us Saqib Fraz il 10 Ott 2020
is findgroups latest command ? Because I am using the 2015a !! and it says undefined function of findgroups
Najam us Saqib Fraz
Najam us Saqib Fraz il 10 Ott 2020
is there any other way of doing it ?

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by