Reshape matrix in the desired form
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Konstantinos Tsitsilonis
      
 el 3 de Mzo. de 2018
  
    
    
    
    
    Editada: Andrei Bobrov
      
      
 el 3 de Mzo. de 2018
            Hi all,
My problem is that I would like to reshape a specific matrix in the form that I desire for my calculations, however I don't seem to be able to get it exactly as I want. Here is the specific example to my problem:
I have the following code:
 a = [1 2 3 4] ;
 b = [5 6 7 8] ;
 [x, y] = meshgrid(a,b) ;
 A = x ;
 A(:,:,2) = y ;
The above gives me an output as I desire, in the following form:
 A(:,:,1) =
     1     2     3     4
     1     2     3     4
     1     2     3     4
     1     2     3     4
 A(:,:,2) =
     5     5     5     5
     6     6     6     6
     7     7     7     7
     8     8     8     8
At this point, I would like to create another matrix called B, based on A, such that:
 B = [1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 
      5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8] ;
I have tried using reshape to accomplish the above however I cant get this output from it.
Your help would be appreciated,
KR,
KMT.
0 comentarios
Respuesta aceptada
  David Fletcher
      
 el 3 de Mzo. de 2018
        B=[reshape(A(:,:,1)',1,16);reshape(A(:,:,2)',1,16)]
0 comentarios
Más respuestas (1)
  Andrei Bobrov
      
      
 el 3 de Mzo. de 2018
        
      Editada: Andrei Bobrov
      
      
 el 3 de Mzo. de 2018
  
      a = [1 2 3 4] ;
b = [5 6 7 8] ;
B = [repmat(a,1,4);repelem(b,4)];
or
reshape(permute(A,[2,1,3]),[],2)';
0 comentarios
Ver también
Categorías
				Más información sobre Creating and Concatenating Matrices 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!


