Select multiple ranges from a column based on their value and insert the mean of those values into a new matrix
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I have a matrix e.g. 20x2 consisting two measurements (M1 and M2). I want to select all M1 as long as M2 is above a value (e.g. from 1-5) and calculate the mean of M2 and insert the resulting mean in a new matrix. Then take the next M2 values (e.g. from 15-20), calculate the mean and add it to the new matrix as long as M1 is above a value. The resulting matrix should include only the mean values based on matrix 1.
How can I do that?
0 Kommentare
Antworten (1)
KSSV
am 14 Jun. 2018
A = rand(20,2) ; % random data for demo
R = [0. 0.5 ; 0.5 1.] ; % ranges
iwant = zeros(size(R,1),2) ;
M1 = A(:,1) ; M2 = A(:,2) ;
for i = 1:size(R,1)
idx = M2>=R(i,1) & M2<R(i,2) ;
iwant(i,1) = mean(M1(idx)) ;
iwant(i,2) = mean(M2(idx)) ;
end
Siehe auch
Kategorien
Mehr zu Numeric Types 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!