matrix automation problem

조회 수: 5 (최근 30일)
joey vergara
joey vergara 2012년 5월 2일
[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

답변 (1개)

Richard Brown
Richard Brown 2012년 5월 2일
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.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by