How to avoid for-loop here; repmat
    3 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Pete sherer
 el 17 de Sept. de 2018
  
    
    
    
    
    Comentada: Star Strider
      
      
 el 17 de Sept. de 2018
            Hi Could anyone help suggest a faster way to construct this vector?
xval = [1 2 7 9];
numX = [1 4 2 3];
% I want final output to be [1 2 2 2 2 7 7 9 9 9];
fullX = [];
for runi=1:length( xval)
    tval   = xval( runi);
    n      = numX( runi);
    if n > 0
        fullX= [ fullX; repmat( tval, n, 1)];
    end 
end %
0 comentarios
Respuesta aceptada
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!