Error Undefined Function or Variable 'Sample'

3 vues (au cours des 30 derniers jours)
Anthony Nelson
Anthony Nelson le 25 Sep 2018
Commenté : James Tursa le 25 Sep 2018
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 commentaire
James Tursa
James Tursa le 25 Sep 2018
You will need to get the code for the sample( ) function from your lab computer.

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 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?

Catégories

En savoir plus sur Function Handles dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by