How can I get the diagonal elements of a matrix to be 0's

조회 수: 5 (최근 30일)
A123456
A123456 2016년 1월 6일
댓글: dpb 2016년 1월 8일
How can I get the diagonal elements of a matrix to have all 0's and 1's everywhere else?

채택된 답변

Walter Roberson
Walter Roberson 2016년 1월 6일
x = ones(N) - eye(N)

추가 답변 (1개)

dpb
dpb 2016년 1월 6일
  댓글 수: 5
Walter Roberson
Walter Roberson 2016년 1월 7일
I would probably use +0 as well, but writing double() explicitly is clearer to people about what is being done and why. People tend to expect that adding 0 will leave everything unchanged...
dpb
dpb 2016년 1월 8일
In the forum if I'd bothered to do the conversion I'd've added a comment on the purpose. As was, I figured the expression alone did satisfy the question and the remainder could be "exercise for the student"...

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

카테고리

Help CenterFile Exchange에서 Matrix and Vector Construction에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by