repeat rows in a matrix based on values in one column
    2 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Masih Alavy
 el 23 de Feb. de 2019
  
    
    
    
    
    Respondida: dpb
      
      
 el 24 de Feb. de 2019
            Hello All, 
I have a matrix which is attached here. Here is what I want to do: I want to make a duplicate of rows whose first column values are the same and then put the duplicate right beneath when the value of the first column changes. I have put a picture for portion of the final file that I want. Thanks for your help. 
0 comentarios
Respuesta aceptada
  dpb
      
      
 el 24 de Feb. de 2019
        u=unique(x(:,1),'stable');       % get the unique values in first column to work over; keep original order
xx=[];
for i=numel(u):1
  ix=find(x(:,1)==u);
  xx=[xx;repmat(x(ix,:),2,1)];   % build the new output array
end
"Deadahead" to just copy the sections to a new file; if not _terribly large x the dynamic reallocation shouldn't be too bad.
0 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Matrix Operations 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!

