# 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)
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
Victor Popa-Simil on 7 Dec 2019
The person has an inherent value of 100 or say 100 objects for example. And when they interact with another randonmly selected individual one will win an object (+1) and another will lose that object (-1). One iteration is a random selection of two individuals who interact. The second iteration will be another random selection of two individuals and it can be the same individuals as selected in the first as well. I was confused on how to show this process. I was able to achieve the first iteration but I couldn't complete the rest of the 10,000.

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)
##### 1 CommentShowHide None
Victor Popa-Simil on 7 Dec 2019
Thank you!

### Community Treasure Hunt

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

Start Hunting!

Translated by