Creating a loop to assign 20 players to two teams and deleting columns
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I am working on a project that includes seperating 20 players to two teams: TeamA and TeamB. I have created a 3x20 matrix which includes player jerseys from 1-20, the second row is random free throw percentages from 50-90, and the third row is random average # of turnovers per game from 0-8. TeamA desires highest free throw percentage and TeamB desires lowest turnovers per game. Before each team can pick, a coin flip is done to decide which team picks each round. Both teams will recieve 10 players each. My question: is my loop correct? Here is my code so far... This is only helping me with a small part of my project, thanks.
numPlayers = 20;
ftPercent = randi([50,90],1,numPlayers);
avgNumTurnover = randi([0,8],1,numPlayers);
playerInfo = [1:1:numPlayers;ftPercent;avgNumTurnover];
coinFlip = round(rand(1,1));
% A 1 from the coinFlip is a heads
% A 0 from the coinFlip is a tails
for i = 1:numPlayers
if coinFlip == 1
TeamA = max(playerInfo(:,2))
else
TeamB = min(playerInfo(3,:))
end
end
0 commentaires
Réponses (1)
Walter Roberson
le 13 Mar 2024
numPlayers = 20;
ftPercent = randi([50,90],1,numPlayers);
avgNumTurnover = randi([0,8],1,numPlayers);
playerInfo = [1:1:numPlayers;ftPercent;avgNumTurnover];
TeamA = [];
TeamB = [];
coinFlip = round(rand(1,1));
% A 1 from the coinFlip is a heads
% A 0 from the coinFlip is a tails
for i = 1:numPlayers
if coinFlip == 1
[~,TeamA(end+1)] = max(playerInfo(:,2));
playerInfo(TeamA(end),2:3) = 0;
else
[~,TeamB(end+1)] = min(playerInfo(3,:));
playerInfo(TeamB(end),2:3) = 0;
end
end
Your coinflip logic is definitely wrong though... You currently have arranged so that if the coinFlip is 1 then teamA gets all 20 players, and otherwise TeamB gets all 20 players.
0 commentaires
Voir également
Catégories
En savoir plus sur General Physics dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!