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

528 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 10 de Dic. de 2021
Editada: MathWorks Support Team el 13 de Dic. de 2021
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 comentario
Steven Lord
Steven Lord el 21 de Mzo. de 2018
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by