Improve speed of NORMRND for a family of distributions in MATLAB

前端 未结 1 1479
感动是毒
感动是毒 2020-12-12 05:04

So, I am looking for a way to speed up my code. I have a large vector of normal distributions (i.e. a vector of means and standard deviations) that I need to generate random

相关标签:
1条回答
  • 2020-12-12 05:56

    Hacked into normrnd.m to get this customized code that must replicate the functionality depicited in the problem -

    N=1e6;
    mu = rand(N,1);
    sigma = rand(N,1);
    temp = randn(size(sigma)).*sigma + mu;
    

    On my system, the runtime was reduced from 18.946094 seconds to 0.037229 seconds.

    Hope this works out for you!

    0 讨论(0)
提交回复
热议问题