Search code examples
arraysmatlabsortingnormal-distribution

Probability density function with large mu and sigma values?


I am using the following function :

 pd=makedist('normal',mu,sigma);
 y = pdf(pd,speed)

The size of mu and sigma is 50x1 and X size is 3000x1. passing one value of mu,sigma and speed at a time, I am getting the output. But how I can pass all these values at the same time so that at the end I will get a data set containing all y values?

I think I have to use a for loop but am unsure how to do it.


Solution

  • mu = rand(50,1);
    sigma = rand(50,1);
    speed = rand(3000,1);
    y = zeros(numel(mu),numel(speed));
    
    for k = 1:numel(mu)
        pd = makedist('normal',mu(k),sigma(k));
        y(k,:) = pdf(pd,speed);  %store in for loop
    end
    

    By initialising the output one can easily double-loop to calculate all components. Your ouput is now indexed as y(mu/sigma,speed), thus the first index corresponds to the mu/sigma pair and the second to the speed entry used.