Error Undefined Function or Variable 'Sample'

2 visualizaciones (últimos 30 días)
Anthony Nelson
Anthony Nelson el 25 de Sept. de 2018
Comentada: James Tursa el 25 de Sept. de 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 comentario
James Tursa
James Tursa el 25 de Sept. de 2018
You will need to get the code for the sample( ) function from your lab computer.

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 25 de Sept. de 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?

Categorías

Más información sobre Function Handles en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by