Lower Triangle of Matrix

조회 수: 8 (최근 30일)
Alex Baham
Alex Baham 2020년 4월 2일
댓글: John D'Errico 2020년 4월 2일
I know that if you have a matrix A, triu(A) will fill the lower triangular matrix with zeros, but is there a way to make that ones instead of zeros? Thanks!

채택된 답변

John D'Errico
John D'Errico 2020년 4월 2일
No. You cannot tell triu to fill with ones instead of zeros. That does not mean what you are asking is impossible, just that you need to be creative in how you use these tools.
A = magic(5)
A =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
triu(A) + tril(ones(size(A)),-1)
ans =
17 24 1 8 15
1 5 7 14 16
1 1 13 20 22
1 1 1 21 3
1 1 1 1 9
  댓글 수: 2
Alex Baham
Alex Baham 2020년 4월 2일
thanks so much! that worked perfectly!!
John D'Errico
John D'Errico 2020년 4월 2일
:)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by