Loopless function calls on vector/matrix members in Matlab/Octave

前端 未结 4 1628
走了就别回头了
走了就别回头了 2021-01-18 23:08

I came into matrix world from loop world (C, etc)

I would like to call a function on each individual member of a vector/matrix, and return the resulting vector/matri

4条回答
  •  盖世英雄少女心
    2021-01-18 23:53

    ARRAYFUN (and its relatives) is the usual way to do that.

    But in your particular case, you can just do

    mycurve = a*exp(-(d-b).^2/(2*c^2));
    

    It's not just syntactic sugar; eliminating loops makes your code run substantially faster.

提交回复
热议问题