Reputation: 77
I have a vector A
with 400 values, and I need another vector B
with 100 values, where every value is the mean of the corresponding 4 values in A
. For example, the first value of B
would be the mean of the 1st-4th values of A
, the second value of B would be the mean of the 5th-8th values of A
, and so on. How can I do this in MATLAB?
Thank you very much!
Upvotes: 0
Views: 63
Reputation: 21563
Here is an alternate solution.
I have expanded it a bit so it will also work if the vector is not an exact multiple of four:
A = 1:399;
B = NaN(4,ceil(length(A)/4));
B(1:length(A))=A;
nanmean(B)
Upvotes: 1