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

1 次查看(过去 30 天)
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"...

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by