Unspecified behaviour of function imag.

2 ビュー (過去 30 日間)
Noah Tang
Noah Tang 2021 年 11 月 30 日
回答済み: Walter Roberson 2021 年 11 月 30 日
In version '9.10.0.1602886 (R2021a)', running
imag part
ans = 1×4
0 0 0 0
will return
[0 0 0 0]
ans = 1×4
0 0 0 0
I accidentally found this when trying to type "imagpart". How does this happen? Will it affect our program in other unanticipated ways?

採用された回答

Walter Roberson
Walter Roberson 2021 年 11 月 30 日
This will not affect your code.
When you call
imag part
that is the same as if you had invoked
imag('part')
which is calling imag() on the vector of four characters, 'p', 'a', 'r', 't' .
In many circumstances, characters automatically convert to the numeric codes used to internally encode the characters, such as 112 for 'p', and 97 for 'a' . So imag() treats this as a vector of real-valued double precision numbers. But the imaginary() portion of those is all 0 so 0 0 0 0 gets returned.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by