Why do I get warning messages about 'Imaginary Parts of Complex X and/or Y Arguments Ignored' ?

조회 수: 532 (최근 30일)
Why do I get the following error message:
ERROR: Warning: Imaginary parts of complex X and/or Y arguments ignored.
Warning: Imaginary parts of complex X, Y, and/or Z arguments ignored.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2021년 12월 10일
편집: MathWorks Support Team 2021년 12월 13일
Explanation:
You are attempting to plot using two complex inputs to a plotting function, like PLOT or PLOT3. In this case, MATLAB will plot using the real part of the first input as the independent variable X and the real part of the second input as the dependent variable Y.
Common causes:
You have performed a square root or FFT operation on the vectors you are attempting to plot, and those operations resulted in a complex vector. Alternatively, you used the variables i and/or j in the computation of your input vectors but those variables did not exist when you performed your computation. In this case, MATLAB will treat i and/or j as the imaginary unit.
Solution:
Stop MATLAB on the line where the warning occurs. Verify that the two vectors or matrices you pass to the PLOT function, or the three you pass to PLOT3, are not complex. If you want to plot the real part of a vector versus the complex part, pass the vector as a single complex vector to the PLOT function. If you want to plot the magnitude of the elements, use the ABS function on the vector before passing it to the PLOT function.
Example demonstrating this warning:
ImaginaryPartIgnored.m
  댓글 수: 1
Steven Lord
Steven Lord 2018년 3월 21일
Adam, where on the standard 2-D axis should the point with coordinates (1+2i, 3) be drawn?
If only the X coordinate can be complex while the Y coordinate must be real or vice versa you could use the real, imag, and plot3 functions.
v = 1:10;
x = v + 1i*v.^2;
y = abs(x);
plot3(real(x), imag(x), y)
xlabel('real(x)');
ylabel('imag(x)');
zlabel('y')
Or you could use abs to take the absolute value of your coordinates as stated in the Support team's answer, or you could find some other way to generate real values from your complex values for purposes of plotting.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by