Why won't it go through the ifelse statement when the if statement isn't satisfied?
    3 views (last 30 days)
  
       Show older comments
    
    Jacob Savona
 on 17 Feb 2015
  
    
    
    
    
    Edited: Roger Stafford
      
      
 on 17 Feb 2015
            A= zeros(3,10);
A(1,:,:)=[1:10];
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);
for d=[1:1:10]
    j=10;
    k=9;
    if rem(d,2)==1;
    for e=[1:1:j]
    if A(2,e,:)== max(B)
        p=e;
        team_A(:,2,:)=A(:,p,:);
        A(:,p)=NaN;
    end
    end
    elseif rem(d,2)==0
        for f=[1:1:k]
            if A(2,f,:)== max(C)
            i=f;
            team_B(:,2,:)=A(:,i,:);
            A(:,i)=NaN;
            end
        end
    end
    j=j-2;
    k=k-2;
end
Accepted Answer
  Roger Stafford
      
      
 on 17 Feb 2015
        
      Edited: Roger Stafford
      
      
 on 17 Feb 2015
  
      It is highly unlikely that any random element in the second row of A would happen to be exactly equal to the maximum integer of the third row in the line
   if A(2,f,:)== max(C)
The odds are one in a thousand million million or thereabouts. For that reason it is equally unlikely that the 'elseif' would ever lead to a change in team_B.
0 Comments
More Answers (0)
See Also
Categories
				Find more on Loops and Conditional Statements in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!