필터 지우기
필터 지우기

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 CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by