Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

not sure what is going wrong

2 visualizaciones (últimos 30 días)
Hunter Herrenkohl
Hunter Herrenkohl el 12 de Mzo. de 2019
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
I keep getting this error for my code, "Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in Untitled20 (line 35)
muoppshot =[randi(100,Team1OppShots),1];"
my code is
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);
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:10000
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(i) = muteamprediction - usmteamprediciton; % <-- store value of i_th iteration
end
Game_Prediction_For_Team_1 = mean(Team_1_Prediction(i))
  4 comentarios
Hunter Herrenkohl
Hunter Herrenkohl el 12 de Mzo. de 2019
That question was partially this code, this is updated
madhan ravi
madhan ravi el 12 de Mzo. de 2019
Editada: madhan ravi el 12 de Mzo. de 2019
No you don’t edit after someone has answered the question!!

Respuestas (1)

Adam Danz
Adam Danz el 12 de Mzo. de 2019
Editada: Adam Danz el 2 de Abr. de 2019
Based on your other lines of code,
muoppshot =[randi(100,Team1OppShots),1];
% _ error
should be
muoppshot =randi(100,Team1OppShots,1);
There are other improvements you can make. The square brackets were not necessary. Also if you're going to define 'n' iterations of your loop, then
for i = 1:n
instead of
for i = 1:10000

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by