How to generate matrix as shown below?
1 回表示 (過去 30 日間)
古いコメントを表示
How Can I generate specific matrix, Such as for n = 3, it shoud generate below three matrices.
% for example n = 3
A = [0 0 0 0; 1 0 0 0;2 1 0 0;3 2 1 0 ] ;
B = [3 0 0 0;2 2 0 0;1 1 1 0;0 0 0 0 ];
C = [0 0 0 0; 0 1 0 0;0 1 2 0;0 1 2 3];
0 件のコメント
回答 (1 件)
Jakob
2020 年 11 月 20 日
n = 3;
A(1,1:n+1) = 0;
for i = 2 : n+1
A(i,1:i-1) = A(i-1, 1:i-1) +1;
end
for i = 1: n+1
B(i,1:i) = (n+1-i);
end
C(1,n+1) = 0;
for i = 2 : n+1
C(i,:) = C(i-1,:);
C(i,i) = C(i,i-1)+1;
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Multidimensional Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!