From: Nicole on
Hi all,

I'm practicing to create exponential random numbers. The following is my code. I can only run it once. When I tried to run the second time, it appeared the error message, "Indexing cannot yield multiple results". I can run my code again if I use clear all. How can I solve it? Thank you!

function [exprand,average,std_dev]=exprand(m,n,h,mu)
exprand=zeros(m,n,h);
exprand=-mu*log(1-rand(m,n,h));
average=sum(sum(exprand))/(m*n);
std_dev=sqrt(sum(sum((exprand-average).^2))/(m*n));
From: Loren Shure on
In article <hkv0fu$nrk$1(a)fred.mathworks.com>, nicolechang1115
@yahoo.com.tw says...
> Hi all,
>
> I'm practicing to create exponential random numbers. The following is my code. I can only run it once. When I tried to run the second time, it appeared the error message, "Indexing cannot yield multiple results". I can run my code again if I use clear all. How can I solve it? Thank you!
>
> function [exprand,average,std_dev]=exprand(m,n,h,mu)
> exprand=zeros(m,n,h);
> exprand=-mu*log(1-rand(m,n,h));
> average=sum(sum(exprand))/(m*n);
> std_dev=sqrt(sum(sum((exprand-average).^2))/(m*n));
>

You have an output variable named the same as the function. That's a
poor idea.

--
Loren
http://blogs.mathworks.com/loren
http://matlabwiki.mathworks.com/MATLAB_FAQ
From: Nicole on
Loren Shure <loren.shure(a)mathworks.com> wrote in message
> You have an output variable named the same as the function. That's a
> poor idea.

Thank you! Solved.