Create a matrix using offset elements of a vector
    6 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    WeiShan Ng
 el 25 de Jun. de 2020
  
    
    
    
    
    Comentada: WeiShan Ng
 el 26 de Jun. de 2020
            Let say I have a vector v = [v1, v2, v3], I would like to create a non-square matrix putting the vector v as tridiagonal elements like this , 
matrix = [v1, v2, v3, 0, 0, 0,..., 0;
                0 , v1,v2,v3, 0, 0 ,...,0;
                0 , 0, v1,v2,v3,0,.....,0;]
I know there's a diag command but it's only for square matrix. What's the way of creating a non-square matrix?
0 comentarios
Respuesta aceptada
  Kanika Gupta
      
 el 25 de Jun. de 2020
        Try blktridiag:
A = blktridiag([1;2],[3;4],[5;6],4); 
full(A) 
ans = 
     1     5     0     0 
     2     6     0     0 
     3     1     5     0 
     4     2     6     0 
     0     3     1     5 
     0     4     2     6 
     0     0     3     1 
     0     0     4     2 
Run help blktridiag for more info
Más respuestas (0)
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!

