採用された回答

Walter Roberson
Walter Roberson 2016 年 1 月 6 日

0 投票

x = ones(N) - eye(N)

その他の回答 (1 件)

dpb
dpb 2016 年 1 月 6 日

0 投票

x=~eye(N);

5 件のコメント

Walter Roberson
Walter Roberson 2016 年 1 月 6 日
Note: that would be a result of type logical rather than a numeric type. x = double(~eye(N)) would be double precision.
dpb
dpb 2016 年 1 月 7 日
That wasn't a a given constraint! :) But, yes, is so...
dpb
dpb 2016 年 1 月 7 日
"x = double(~eye(N)) would be double precision"
or
x = ~eye(N)+0
is what I'd probably actually write, being in favor of minimal keystrokes as a general rule...no idea which might have a performance advantage for increasing N.
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"...

サインインしてコメントする。

タグ

質問済み:

2016 年 1 月 6 日

コメント済み:

dpb
2016 年 1 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by