Apply function to rolling window

前端 未结 5 760
自闭症患者
自闭症患者 2021-02-06 14:42

Say I have a long list A of values (say of length 1000) for which I want to compute the std in pairs of 100, i.e. I want to compute std(A(1:100))

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-06 15:04

    What you're doing is basically a filter operation.

    If you have access to the image processing toolbox,

    stdfilt(A,ones(101,1)) %# assumes that data series are in columns
    

    will do the trick (no matter the dimensionality of A). Note that if you also have access to the parallel computing toolbox, you can let filter operations like these run on a GPU, although your problem might be too small to generate noticeable speedups.

提交回复
热议问题