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

530 次查看(过去 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-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