From a vector to a shorter vector of averages in Matlab -
let have vector x
in matlab of size 1000. want produce vector y
of length 10 each component contains average of 100 records vector x
.
my attempt quite simple
for i=1:10 y(i) = mean(x((1:100)+(i-1)*100)); end
i wonder if there build in command or more elegant solution this.
you can use reshape
-function generate 2d-array , calculate mean on correct dimension.
this works replacement loop:
y = mean(reshape(x,[100,10]),1);
note: not matter if x
column-vector or row-vector.
Comments
Post a Comment