Creating a loop to assign 20 players to two teams and deleting columns

1 次查看(过去 30 天)
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

回答(1 个)

Walter Roberson
Walter Roberson 2024-3-13
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.

类别

Help CenterFile Exchange 中查找有关 General Physics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by