I want the code to repeat for 10,000 times and add the new value to the matrix but I don't know how? Please help.
4 views (last 30 days)
Show older comments
This is my code so far and I added the "for k" and "end" in hopes of making the code loop but it didnt work. The goal of the project is to have values from 1-100 which start out with a value of 100 and then 2 are randomly selected from this group of 100. There is a random choosing of who wins and if they win, their value (100) gets a +1 applied to it. If they lose they get -1. I want 10,000 iterations where any number can be chosen.
nsims = 10000;
for k = 1:nsims
people = [1:100];
for i=1:100
people(i) = 100;
end
simsize = numel(people);
y = (randperm(simsize, 2));
if round(rand) == 0
output = y(2);
else
output = y(1);
end
win = people(y(1)) + 1;
lose = people(y(2)) - 1;
dist = [win; lose];
end
Accepted Answer
JESUS DAVID ARIZA ROYETH
on 7 Dec 2019
nsims = 10000;
people = repmat(100,1,100);
simsize = numel(people);
for k = 1:nsims
y = randperm(simsize, 2);
if round(rand) == 0
win=y(1);
lose=y(2);
else
win=y(2);
lose=y(1);
end
people(win)=people(win)+1;
people(lose)=people(lose)-1;
end
disp(people)
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!