Matrix whose elements are the colums numbers
1 回表示 (過去 30 日間)
古いコメントを表示
Hi,
I need to create a 100*100 matrix with 3 conditions :
- elements on the diagonal are 0
- elements below the diagonal contain the column number
- elements above the diagonal contain the column number with minus sign
it may look simple but I am really new here so I hope someone could help me out :)
thanks in advance
0 件のコメント
回答 (1 件)
David Hill
2021 年 3 月 12 日
n=100;
[a,b]=ind2sub([n,n],1:n^2);
b(b==a)=0;
b(b>a)=-b(b>a);
c=reshape(b,[n,n]);
2 件のコメント
David Hill
2021 年 3 月 12 日
If you a satisfied with the answer, you should accept it to close out the question.
参考
カテゴリ
Help Center および File Exchange で Operating on Diagonal Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!