Unspecified behaviour of function imag.
조회 수: 2 (최근 30일)
이전 댓글 표시
In version '9.10.0.1602886 (R2021a)', running
imag part
will return
[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?
댓글 수: 0
채택된 답변
Walter Roberson
2021년 11월 30일
This will not affect your code.
You are encountering Command/Function Duality https://www.mathworks.com/help/matlab/matlab_prog/command-vs-function-syntax.html
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!