Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Looping the column elements of the Matrix

조회 수: 1 (최근 30일)
Najam us Saqib Fraz
Najam us Saqib Fraz 2020년 10월 9일
마감: MATLAB Answer Bot 2021년 8월 20일
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
Najam us Saqib Fraz
Najam us Saqib Fraz 2020년 10월 10일
is there any other way of doing it ?

태그

Community Treasure Hunt

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

Start Hunting!

Translated by