Error Undefined Function or Variable 'Sample'
2 次查看(过去 30 天)
显示 更早的评论
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
2018-9-25
You will need to get the code for the sample( ) function from your lab computer.
回答(1 个)
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?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Handles 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!