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

532 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 10 Déc 2021
Modifié(e) : MathWorks Support Team le 13 Déc 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 commentaire
Steven Lord
Steven Lord le 21 Mar 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by