how can I fix Warning: Imaginary parts of complex X and/or Y arguments ignored.

18 visualizaciones (últimos 30 días)
Hi
I'm trying to plot my code but this warning shows up
Warning: Imaginary parts of complex X and/or Y arguments ignored
clear all
close all
clc
T=2;
f=1/T;
w=2*pi*f;
t=-T/2:0.0001*T:T/2;
s=0;
for n=-100:100
C=-8*1j*(-cos(n*pi/2)/(8*n*pi)+(sin(n*pi/2)/((2*n*pi)^2)));
if n==0
c=0;
end
s=s+C*exp(1j*n*w*t);
end
s=s;
plot(t,s)

Respuestas (1)

Adam Danz
Adam Danz el 4 de Oct. de 2020
Editada: Adam Danz el 5 de Oct. de 2020
Your data contain complex numbers.
If this is unexpected, it indicates that there's a problem somewhere along your pipeline and you should figure out where the imaginary parts are coming from. For example, are you taking the square root of a negative number?
To find which elements of a vector are imaginary,
isImaginary = A ~= real(A);
If imaginary parts are expected and you'd like to remove them,
A_real = real(A);

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by