Move multiple rows to specified postion
    2 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Rishi Balasubramanian
 el 23 de Dic. de 2020
  
    
    
    
    
    Editada: Rishi Balasubramanian
 el 23 de Dic. de 2020
            Hello,
I have a mxn matrix of binary data. I want to write a code where I move multiple rows to specified position or index.
%For example consider my matrix
%    a b c d e f g h i j k l
H = [0 0 1 1 0 1 0 1 0 1 1 0;  %1
     0 0 0 1 0 1 1 0 1 0 1 0;  %2
     0 1 1 0 0 1 1 1 0 0 0 1;  %3
     0 1 1 0 1 0 1 0 1 0 0 1;  %4
     0 0 0 1 1 0 0 1 1 0 0 0;  %5
     0 1 0 0 1 0 0 0 0 0 1 0]; %6
%I want to move rows 3&4 to between 5&6.
%I want my resultant matrix to be -
%    a b c d e f g h i j k l
H = [0 0 1 1 0 1 0 1 0 1 1 0;  %1
     0 0 0 1 0 1 1 0 1 0 1 0;  %2
     0 0 0 1 1 0 0 1 1 0 0 0;  %5
     0 1 1 0 0 1 1 1 0 0 0 1;  %3
     0 1 1 0 1 0 1 0 1 0 0 1;  %4
     0 1 0 0 1 0 0 0 0 0 1 0]; %6
% I want  generalised code to keep changing select rows in a loop.
0 comentarios
Respuestas (1)
  KALYAN ACHARJYA
      
      
 el 23 de Dic. de 2020
        
      Editada: KALYAN ACHARJYA
      
      
 el 23 de Dic. de 2020
  
      I suupose there are no condition this time, assumed the row number arbitarity?? Any logic of shifting positions?
H_result=[H([1,2,5],:);H([3,4],:);H(5,:)]
Ver también
Categorías
				Más información sobre Matrix Indexing 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!

