How do I create a vectorized version of randsample in Matlab

大憨熊 提交于 2019-12-12 03:24:32

问题


I have a support (supp_epsilon) and a probability mass function (pr_mass_epsilon) in Matlab, constructed as follows.

    supp_epsilon=[0.005 0.01;
                  0.01  0.015;
                  0.015 0.02;
                  0.02  0.025]; 

    suppsize_epsilon=size(supp_epsilon,1);

    pr_mass_epsilon=zeros(suppsize_epsilon,1);

    mu_epsilon=[0; 0];
    sigma_epsilon=[1 0.5; 0.5 1];

    pr_mass_epsilon=zeros(suppsize_epsilon,1);

    for j=1:suppsize_epsilon
 pr_mass_epsilon(j)=mvnpdf(supp_epsilon(j,:),mu_epsilon.',sigma_epsilon)/sum(mvnpdf(supp_epsilon,mu_epsilon.',sigma_epsilon));
     end

Note: supp_epsilon is 4x2. Each 1x2 row of supp_epsilon is an element of the support of interest.

Question: I want to draw n=10 vectors of size 1x2 from pr_mass_epsilon. Each of these vectors has to be a row of supp_epsilon. For n very large the empirical frequency of the drawn vectors has to be close to pr_mass_epsilon.

How can I do this?

Note: This question addresses the scalar case where the answer suggests to use randsample.

来源:https://stackoverflow.com/questions/58631801/how-do-i-create-a-vectorized-version-of-randsample-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!