How to reshape a matrix from a vector?
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    TRAILOKYA
 el 14 de Oct. de 2014
  
    
    
    
    
    Editada: Sean de Wolski
      
      
 el 14 de Oct. de 2014
            I have a vector of 105 elements where the sizes are not compatible for a matrix. I want to make it a 2 dimensional matrix by adding zeros at last so that it becomes compatible for the matrix. Would you please tell me how can i do it?
0 comentarios
Respuesta aceptada
  Thorsten
      
      
 el 14 de Oct. de 2014
        
      Editada: Thorsten
      
      
 el 14 de Oct. de 2014
  
      If, e.g., 200 is the desired size, just use
vec(200) = 0;
All values between 105 and 200 will be filled with zeros.
1 comentario
  John
 el 14 de Oct. de 2014
				Hello, use the reshape command.
Consider that your matrix has to be m x n (rows x columns) = total number of elements. Then do what Thorsten says vec(totalNumberOfElements) = 0, then
Matrix = reshape(vec,m,n).
Remember that rows run faster than columns... That is, the elements will be ordered in a row fashion way.
Más respuestas (1)
  Sean de Wolski
      
      
 el 14 de Oct. de 2014
        
      Editada: Sean de Wolski
      
      
 el 14 de Oct. de 2014
  
      If you want a 100x2 from a 105 element vector, padding with zeros, this should do it:
buffer(1:105,100)
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!



