to find average value in a particular range of a matrix
8 views (last 30 days)
Show older comments
hai
i am having a matrix with values of size 1*700 i have to find the avg value of first 1 to 100 ,avg value of 100 - 200 and so on upto 600 -700 is there any function to find the average of 1 -100 and 100 - 200, 200 - 300,300 - 400,400 - 500,500 - 600,600 - 700,
0 Comments
Answers (1)
Andrei Bobrov
on 19 Sep 2011
variant 1 for the intervals: 1:100, 101:200,...,601:700
out = mean(reshape(yourmtx,100,[]));
variant 2 for the intervals: 1:100, 101:200,...,601:700
out = blkproc(yourmtx,[1 100],@mean)
variant 3 for the intervals: 1:100, 100:200,...,600:700
idx = bsxfun(@plus,0:100,(0:100:600)')';
idx(1) = 1;
mv = yourmtx(idx);;
mv(1)=nan;
out = nanmean(mv);
variant 4 for the intervals: 1:100, 100:200,...,600:700
out = mean(reshape(yourmtx,100,[]));
out(2:end) = mean([yourmtx(100:100:600);out(2:end)]);
1 Comment
Daniel
on 27 Jan 2012
Hello andrei.
I am having more or less the same problem.
But I need to extract mean values within a certain range of a matrix. This range is given by each column's min and max value, and a step.
Basically I've done the next:
1. I have a 2x720 matrix with data, let's call it A.
2. I calculate a = max(A), b = min(A).
3. I apply the histcnd function (which counts frequency of values within certain edges or range).
4. The edges = {b(1):2:a(1),b(2):10:a(2)}, that is from min and max value of each column of A, with a certain step (2 and 10).
This returns an answer matrix, whose dimension depends on the steps given.
This matrix needs to be divised by certain factors, but then, I have to re-multiply it to the values of the first matrix A. The problem? Matrixs dimension do not fit to do so. The solution would be to obtain a new matrix from A, containing mean values within each column given range (the ones used on 'edges').
Is this posible?
Thanks a lot!
See Also
Categories
Find more on Numeric Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!