Clear Filters
Clear Filters

Run many iterations of a code

1 view (last 30 days)
Hunter Herrenkohl
Hunter Herrenkohl on 12 Mar 2019
Edited: Adam Danz on 12 Mar 2019
  1 Comment
Adam Danz
Adam Danz on 12 Mar 2019
Edited: Adam Danz on 12 Mar 2019
The original code that was part of this question is here
Q1 = 'How many shots does Team 1 shoot per game?';
Team1Shots = input(Q1);
Q2 = 'What is Team 1s overall shooting percentage? (40.0 percent is entered as 40.1)';
Team1ShotPCT = input(Q2);
Q5 = 'What percentage of total Team 1 shots are 3s? (40.0 percent is entered as 40.1)';
Team1ShotType = input(Q5);
Q7 = 'How many shots do Team 1s opponents take per game?'
Team1OppShots = input(Q7);
Q8 = 'What do teams shoot overall against Team 1?(percentage)';
Team1OppShotPCT = input(Q8);
Q9 = 'What percent of shots taken against Team 1 are 3s?';
Team1OppShotType = input(Q9)
Q3 = 'How many shots does Team 2 shoot per game?';
Team2Shots = input(Q3);
Q4 = 'What is Team 2s overall shooting perentage? (40.0 percent is entered as 40.1)';
Team2ShotPCT = input(Q4);
Q6 = 'What percentage of total Team 2 shots are 3s? (40.0 percent is entered as 40.1)';
Team2ShotType = input(Q6);
Q10 = 'How many shots do Team 2s opponents take per game?';
Team2OppShots = input(Q10);
Q11 = 'What do teams shoot overall against Team 2? (percentage)';
Team2OppShotPCT = input(Q11);
Q12 = 'What percentage of shots taken against Team 2 are 3s?';
Team2OppShotType = input(Q12);
mushot = [randi(100,Team1Shots,1)];
mushot(mushot < 100-Team1ShotPCT)=0;
mushot(mushot > 100-Team1ShotPCT)=1;
mushottype = [randi(100,Team1Shots,1)];
mushottype(mushottype < 100-Team1ShotType)=2;
mushottype(mushottype > 100-Team1ShotType)=3;
muoppshot =[randi(100,Team1OppShots),1];
muoppshot(muoppshot < 100-Team1OppShotPCT)=0
muoppshot(muoppshot > 100-Team1OppShotPCT)=1
muoppshottype = [randi(100,Team1OppShots,1)];
musopphottype(muoppshottype < 100-Team1OppShotType)=2;
muoppshottype(muoppshottype > 100-Team1OppShotType)=3;
mushot;
mushottype;
mupointarray =[mushot(:) .* mushottype(:)];
mupoints = sum(mupointarray(:));
muopppointsarray = [muoppshot(:) .* muoppshottype(:)];
muopppoints = sum(muopppointsarray(:));
muteamprediction = mupoints *0.8 - muopppoints *0.2;
usmshot = [randi(100,Team2Shots,1)];
usmshot(usmshot < 100-Team2ShotPCT)=0;
usmshot(usmshot > 100-Team2ShotPCT)=1;
usmshottype = [randi(100,Team2Shots,1)];
usmshottype(usmshottype < 100-Team2ShotType)=2;
usmshottype(usmshottype > 100-Team2ShotType)=3;
usmoppshot = [randi(100,Team2OppShots,1)];
usmoppshot(usmoppshot < 100-Team2OppShotPCT)=0;
usmoppshot(usmoppshot > 100-Team2OppShotPCT)=1;
usmoppshottype = [randi(100,Team2OppShots,1)];
usmoppshottype(usmoppshottype < 100-Team2OppShotType)=2;
usmoppshottype(usmoppshottype > 100-Team2OppShotType)=3;
usmshot;
usmshottype;
usmpointsarray = [usmshot(:) .* usmshottype(:)];
usmpoints = sum(usmpointsarray(:));
usmopppointsarray = [usmoppshot(:) .* usmoppshottype(:)];
usmopppoints = sum(usmopppointsarray(:));
usmteamprediction = usmpoints *0.8 - usmopppoints*0.2;
Team_1_Prediction= muteamprediction - usmteamprediciton;

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 12 Mar 2019
Edited: Adam Danz on 12 Mar 2019
Here's a template
n = 1000; %number of iterations
Team_1_Prediction = zeros(1,n); %here's where we'll store the output of each iteratoin
% loop through each iteration
for i = 1:n
mushot = [randi(100,Team1Shots,1)];
% [insert the rest of your code here]
Team_1_Prediction(i) = mupoints - usmpoints; % <-- store value of i_th iteration
end

More Answers (0)

Categories

Find more on Video games in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!