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

조회 수: 2 (최근 30일)
Peter
Peter 2024년 3월 13일
편집: Peter 2024년 3월 26일
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