Error Undefined Function or Variable 'Sample'

2 views (last 30 days)
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 Comment
James Tursa
James Tursa on 25 Sep 2018
You will need to get the code for the sample( ) function from your lab computer.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 25 Sep 2018
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?

Categories

Find more on Function Handles in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!