Asked by J K
on 27 Jul 2019

Hi guys,

I have this code and upon execution Matlab says that Imaginary parts of complex X and/or Y arguments were ignored. How can I plot the function without ignoring imaginary parts? I tried "plot(t, real(squeeze(shifted(:,61,61))),imag(squeeze(shifted(:,61,61))), '.-');" but Matlab said "Data must be a single matrix Y or a list of pairs X,Y" Tried a few other things but they did not work either.

Here is the full code before any modifications and attempts.

c = 0.3; % um/fs

z = 5;

w_o = 2*pi*c;

w = -6*w_o:0.1:6*w_o;

dw = w(2)-w(1);

kx = -6:0.1:6;

dkx=kx(2)-kx(1);

ky = kx;

dky = ky(2)-ky(1);

delta =pi;

deltaW = 3*pi;

deltaK = 1;

nw = length(w);

dt = pi/w(end);

t =[(-nw/2+1:nw/2)]*dt;

nkx = length(kx);

dx = pi/kx(end);

x =[(-nkx/2+1:nkx/2)]*dx;

nky = length(ky);

dy = pi/ky(end);

y = [(-nky/2+1:nky/2)]*dy;

[Kx, W, Ky] = meshgrid(kx, w, ky);

[X, T, Y] = meshgrid(x, t, y);

input = exp(-((W-w_o).^2)/deltaW.^2).*exp(-(Kx.^2+Ky.^2)/(deltaK.^2)).*exp(1*i.*sqrt((W/c).^2-(Kx.^2+Ky.^2)).*z(j));

fourier = fftn(fftshift(input));

shifted = fftshift(fourier);

figure(6);

plot(t, squeeze(shifted(:,61,61)), '.-');

Answer by Walter Roberson
on 27 Jul 2019

plot(t, real(shifted(:, 61, 61)), '.-b', t, imag(shifted(:, 61, 61)), '.-r')

Where does your code define shifted?

Walter Roberson
on 27 Jul 2019

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Walter Roberson (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/473735-plot-a-function-consisting-of-real-and-imaginary-numbers#comment_729076

## Rena Berman (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/473735-plot-a-function-consisting-of-real-and-imaginary-numbers#comment_747763

Sign in to comment.