How to generate mixed exponential distribution random number using the command in MATLAB?

How to generate mixed exponential distribution random number using the command in MATLAB? because mixexprnd function does not exist in R2013. Thank you for your help

 Accepted Answer

https://de.mathworks.com/matlabcentral/fileexchange/29136-stochastic-weather-generator--weagets-?focused=3858295&tab=function
Best wishes
Torsten.

3 Comments

function R = mixexprnd(p,mu1,mu2,n) does not exist in Matlab 2016. error while running this function. This function serves for StoRainGen toolbox- is it I need to have StoRainGen toolbox for mixed exponential distribution?
Why don't you just copy the code from the afore mentioned link, save it as a .m-file and call it to generate your random numbers ?
Best wishes
Torsten.
Okay,I will try first. Thank you Torsten for your help.

Sign in to comment.

More Answers (1)

Hello Noor, The function below agrees with the function cited above for several choices of parameters that I have tried. For 10000 points, cited function takes 40 sec. and this function takes .009 sec.
function R = randmixexp(a,b1,b2,n)
%
% random numbers taken from mixed exponential distribution
% pdf = a*(1/b1)*exp(-x/b1) + (1-a)*(1/b2)*exp(-x/b2)
% cdf = a*(1-exp(-x/b1)) + (1-a)*(1-exp(-x/b2))
%
% R = randmixexp(a,b1,b2,n)
if nargin < 4; n=1; end
r = rand(1,n);
ind = r<a;
nind = ~ind;
r = rand(1,n);
R(ind) = -log(r(ind))*b1;
R(nind) = -log(r(nind))*b2
% David Goodmanson

3 Comments

Okay I will try it first.. Thank you David for your help.
David, it shows function R = randmixexp(a,b1,b2,n) not enough input argument.. what is mean by that?
I guess it is telling you that you are not supplying enough input arguments to the function. I just tried randmixexp(.2,1,2,100) and it worked fine.

Sign in to comment.

Categories

Asked:

on 19 Apr 2017

Commented:

on 20 Apr 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!