how to append values in a vector in for loop?
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    sheno39
 el 14 de Mayo de 2014
  
    
    
    
    
    Editada: Andrei Bobrov
      
      
 el 14 de Mayo de 2014
             out=[0 1;1 3;2 5;3 5; 7 2; 8 1;9 1;11 4];
for i=1:8
if out(i,2)==max(out(:,2))
val=out(i,1)
end
 end
The output i need is 2 and 3, but in my code the variable 'val' stores only 3. I want to store 2 and 3 in the vector 'val. Any one help me?
0 comentarios
Respuesta aceptada
  Andrei Bobrov
      
      
 el 14 de Mayo de 2014
        
      Editada: Andrei Bobrov
      
      
 el 14 de Mayo de 2014
  
      out=[0 1;1 3;2 5;3 5; 7 2; 8 1;9 1;11 4];
k = 0;
for i=1:8
    if out(i,2)==max(out(:,2))
        k = k + 1;
        val(k)=out(i,1);
    end
end
or
val = out(out(:,2)==max(out(:,2)),1);
Más respuestas (0)
Ver también
Categorías
				Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!