Hi, for the following code:
n = 50000;
g = 0.3;
x = [];
for i=1:n
k = 0;
while unifrnd(0,1) < g
k = k + 1;
end
b = 0;
mynumber = 2;
for j = 1:k
switch mynumber
case 1
v = random(beta,3,3)
case 2
v = random(gam,5,5)
case 3
v = random(exp,3)
case 4
v = random(geo,0.2)
case 5
v = random(unif,0,5)
case 6
v = random(norm,0,1)
end
b = b + v;
end
if b ~= 0
x = [x, b];
end
end
I get the following error: Undefined function or variable 'gam'.
Error in test (line 21) v = random(gam,5,5)
why is that? Thanks

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 5 月 29 日

0 投票

You can tell us what is the value of gam?

5 件のコメント

MiauMiau
MiauMiau 2013 年 5 月 29 日
gam(5,5) should be a gamma random variable with shape and scale parameters equal to 5. So I always add one sort of random variable to b.
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 5 月 29 日
Maybe you should use 'gam' instead of gam
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 5 月 29 日
編集済み: Azzi Abdelmalek 2013 年 5 月 29 日
You can't use
v = random(beta,3,3) % you missed ' '
it should be
v = random('beta',3,3)
The same remark for the other options gam, geo,norm,...
MiauMiau
MiauMiau 2013 年 5 月 29 日
ah..so that's it. I will try it
MiauMiau
MiauMiau 2013 年 5 月 29 日
works, thanks!

サインインしてコメントする。

その他の回答 (1 件)

Muruganandham Subramanian
Muruganandham Subramanian 2013 年 5 月 29 日

0 投票

3 件のコメント

MiauMiau
MiauMiau 2013 年 5 月 29 日
The path is set, so it is not a problem with the path but it must be some syntax error
Muruganandham Subramanian
Muruganandham Subramanian 2013 年 5 月 29 日
see, You hav to declare the variable 'gam' and others as global or local, then only you can call it..
MiauMiau
MiauMiau 2013 年 5 月 29 日
But "gam" is just an already defined distribution in matlab...as "normrnd(.." since when has this decleration to be done? And where do I have to do it?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange で Random Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by