Error Undefined Function or Variable 'Sample'

2 ビュー (過去 30 日間)
Anthony Nelson
Anthony Nelson 2018 年 9 月 25 日
コメント済み: James Tursa 2018 年 9 月 25 日
Hi All- i am a matlab noobie for my masters program and am getting an error the first time running this code on my home machine that worked fine in the school computer lab. I am wondering if anyone can help me figure out why? It seems my version of matlab is missing the 'sample' function, whereas it suggests to use 'datasample' or 'randsample' but the way I wrote the code in class it is not working.
Anyone out there that can help?
vote_rate1 = 25;
vote_rate2 = 100;
candidates = [1;0];
vote_prob = [.52;.48];
for trial = 1:1000000
vote1 = sample(candidates,vote_rate1,vote_prob);
vote2 = sample(candidates,vote_rate2,vote_prob);
y(trial) = proportion(vote1==0);
z(trial) = proportion(vote2==0);
end
sum(y(:) > 0.5)/1000000
sum(z(:) > 0.5)/1000000
  1 件のコメント
James Tursa
James Tursa 2018 年 9 月 25 日
You will need to get the code for the sample( ) function from your lab computer.

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

回答 (1 件)

Image Analyst
Image Analyst 2018 年 9 月 25 日
You must have sample defined somewhere at home but not at school. On your home system, put this code in before you refer to sample:
which -all sample
What does it show in the command window, and how is it different than what you see at school?

カテゴリ

Help Center および File ExchangeFunction Handles についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by