Borrar filtros
Borrar filtros

Run many iterations of a code

1 visualización (últimos 30 días)
Hunter Herrenkohl
Hunter Herrenkohl el 12 de Mzo. de 2019
Editada: Adam Danz el 12 de Mzo. de 2019
  1 comentario
Adam Danz
Adam Danz el 12 de Mzo. de 2019
Editada: Adam Danz el 12 de Mzo. de 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;

Iniciar sesión para comentar.

Respuesta aceptada

Adam Danz
Adam Danz el 12 de Mzo. de 2019
Editada: Adam Danz el 12 de Mzo. de 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
  2 comentarios
Hunter Herrenkohl
Hunter Herrenkohl el 12 de Mzo. de 2019
Thank you so much!!
Adam Danz
Adam Danz el 12 de Mzo. de 2019
Glad it worked out!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Video games en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by