フィルターのクリア

how can i write this matrix in matlab?

2 ビュー (過去 30 日間)
mohammad azsad
mohammad azsad 2014 年 11 月 2 日
コメント済み: dpb 2014 年 11 月 3 日
how can i write this matrix in matlab? this matrix is (n+1)*(n+1) that n must be enter by user

採用された回答

Rick Rosson
Rick Rosson 2014 年 11 月 2 日
x = zeros(n+1);
x(1,1:2) = [ 2 1 ];
x(end,end-1:end) = [ 1 2 ];
for k = 2:n
x(k,k1:k+1) = [ 1 4 1 ];
end

その他の回答 (2 件)

dpb
dpb 2014 年 11 月 2 日
Given input n and
r = [1 4 1];
c={repmat(r,n,1)}; % cell array of n copies of r
m=blkdiag([2 1],c{:},[1 2]); % expand c to comma list for blkdiag
clear c

Image Analyst
Image Analyst 2014 年 11 月 2 日
Lots of ways, for loop, addition, assignment, zeros(), etc. I'd probably use eye() and circshift(). Hint:
diagArray = 4 * eye(7)
See what that gives you. Imagine shifting some diagonal arrays with circhsift() and adding the 3 arrays together. That should be enough hint to get you started.
  1 件のコメント
dpb
dpb 2014 年 11 月 3 日
I thought the blkdiag solution kinda' cute, IA... :)
Excepting for needing the temporary cell array; couldn't see a simple way to generate the comma-separated list in one swell foop...

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by