Repeat values in a vector
    3 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Florian
 el 16 de Oct. de 2018
  
    
    
    
    
    Comentada: Florian
 el 17 de Oct. de 2018
            Assume
a1=[1 5 8];
b1=[6 4 5];
a2=[1 2 3 4 5 6 7 8];
Now I want to create a matching vector with values repeated as follows:
b2=[6 6 6 6 4 4 4 5];
Thanks in advance!
2 comentarios
Respuesta aceptada
Más respuestas (1)
  Bruno Luong
      
      
 el 16 de Oct. de 2018
        
      Editada: Bruno Luong
      
      
 el 16 de Oct. de 2018
  
      Another method:
[~,loc] = histc(a2,a1);
b2 = b1(loc)
yet another one
b2 = b1(interp1(a1,1:length(a1),a2,'previous'))
Ver también
Categorías
				Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
			
	Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




