matrix automation problem
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
[c21 c11 c21 0 0 0 0 0 0 0; 0 c21 c11 c21 0 0 0 0 0 0; 0 0 c21 c11 c21 0 0 0 0 0; 0 0 0 c21 c11 c21 0 0 0 0; 0 0 0 0 c21 c11 c21 0 0 0; 0 0 0 0 0 c21 c11 c21 0 0; 0 0 0 0 0 0 c21 c11 c21 0; 0 0 0 0 0 0 0 c21 c11 c21] where the amount of rows/columns depends on a variable m and n respectively m=n-2
and n=10 in this case
how do i "automate" this??? TIA
0 comentarios
Respuestas (1)
Richard Brown
el 2 de Mayo de 2012
This is one annoying case where the sparse version spdiags can do more than the full one diag
n = 10;
m = n-2;
c11 = 1;
c21 = 2;
B = repmat([c21 c11 c21], m, 1);
A = spdiags(B, [0 1 2], m, n);
You might want to use
A = full(spdiags(B, [0 1 2], m, n));
if you don't want a sparse matrix.
0 comentarios
Ver también
Categorías
Más información sobre Resizing and Reshaping 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!