How can I generate a matrix as in the picture?

1 回表示 (過去 30 日間)
xiyou fu
xiyou fu 2016 年 11 月 11 日
編集済み: Andrei Bobrov 2016 年 11 月 11 日
A is the matrix and n is an arbitrary number that larger than 3,thank you very much!

採用された回答

Andrei Bobrov
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 件のコメント
xiyou fu
xiyou fu 2016 年 11 月 11 日
great!thank you!

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
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))]

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by