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

1 Ansicht (letzte 30 Tage)
A123456
A123456 am 6 Jan. 2016
Kommentiert: dpb am 8 Jan. 2016
How can I get the diagonal elements of a matrix to have all 0's and 1's everywhere else?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 6 Jan. 2016
x = ones(N) - eye(N)

Weitere Antworten (1)

dpb
dpb am 6 Jan. 2016
  5 Kommentare
Walter Roberson
Walter Roberson am 7 Jan. 2016
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 am 8 Jan. 2016
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"...

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by