Once I learned what your code was doing, this became a fun exercise!
This works. See if it does what you want:
A= zeros(3,10);
Z=[1:1:10];
A(1,:)=Z;
B=.5+rand(1,10)*.4;
A(2,:)=B;
C=round(1+rand(1,10)*7);
A(3,:)= C;
A
team_A= zeros(3,5);
team_B= zeros(3,5);
k1 = 0;
k2 = 0;
for d=[1:1:10]
if rem(d,2)==1;
k1 = k1 + 1;
p = Z(find(B(Z) == max(B(Z)),1,'first'))
team_A(:,k1)=A(:,p);
Z(Z==p)=[];
end
if rem(d,2) == 0
k2 = k2 + 1;
i = Z(find(C(Z) == max(C(Z)),1,'first'))
team_B(:,k2)=A(:,i);
Z(Z==i)=[];
end
end
I added a counter for each team, and removed the for loops inside the if blocks because they weren‘t necessary (they were actually causing problems). Keeping track of the draft picks turned out to be relatively straightforward. I used your ‘Z’ vector of indices into ‘A’, then each time a player was picked, deleted that player from ‘Z’. I added the ‘ 1,'first' ’ to find calls to avoid duplicate indices. I also deleted the third dimension from your matrices, because it wasn’t needed either. They’re all 2-dimensional as you set them up, so the third dimension was redundant.
I leave you to discover how the rest of my revision of your code works, since it’s all straightforward. (It’s GMT-7 here, and the end of my day.)