フィルターのクリア

Matrix whose elements are the colums numbers

2 ビュー (過去 30 日間)
Noa Prasquier
Noa Prasquier 2021 年 3 月 12 日
コメント済み: David Hill 2021 年 3 月 12 日
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

回答 (1 件)

David Hill
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 件のコメント
Noa Prasquier
Noa Prasquier 2021 年 3 月 12 日
thank you so much !
David Hill
David Hill 2021 年 3 月 12 日
If you a satisfied with the answer, you should accept it to close out the question.

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

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by