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

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -