matrix automation problem
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
[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 Kommentare
Antworten (1)
Richard Brown
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!