How can I generate a matrix as in the picture?
조회 수: 1 (최근 30일)
이전 댓글 표시

A is the matrix and n is an arbitrary number that larger than 3,thank you very much!
댓글 수: 0
채택된 답변
Andrei Bobrov
2016년 11월 11일
편집: Andrei Bobrov
2016년 11월 11일
n = 6; % Let n = 6
z = [-1 3 -3 1];
m = numel(z);
k = n-m+1;
A = full(spdiags(ones(k,1)*z,0:m-1,k,n));
other way with Communications System Toolbox:
n = 6; % Let n = 6
z = [-1 3 -3 1];
A = convmtx(z,n-numel(z)+1);
추가 답변 (1개)
Walter Roberson
2016년 11월 11일
You can add together diag() calls
[diag(-1 * ones(1, n-3)), zeros(n-3,3)] + ...
[zeros(n-3, 1), diag(3 * ones(1, n-3)), zeros(n-3,2)] + ...
[zeros(n-3, 2), diag(-3 * ones(1, n-3)), zeros(n-3,1)] + ...
[zeros(n-3, 3), diag(1 * ones(1, n-3))]
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!