matrix automation problem
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
[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 commentaires
Réponses (1)
Richard Brown
le 2 Mai 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 commentaires
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!