MATLAB: Won’t the imaginary parts of this matix equation show up

matrix array

For some reason, the imaginary portion of this matrix isn't showing up.
%time linespace
t = 0:1/fs:((N-1)/fs);
g = sin(2*f1*pi*t)+B*sin(2*f2*pi*t + phi);
%for an 12-point DFT we need 12 input samples
xn = zeros(1,12);
for i = 1:12
xn(i) = g(i);
end
MN_Matrix = zeros(6,12);
for i = 1:6
for j = 1:12
xn(j).*(cos((((j-1)*2*pi*(i-1))/N))-(j*sin(((j-1)*2*pi*(i-1))/N)));
end
end
disp(MN_Matrix)

Best Answer

Hi Charles,
If I get the intent of the equation, it isn't showing up because you are using j as a do loop index, which sets its values to be real. Once you do that even once, maybe 1000 lines of code before, j is no longer sqrt(-1). So you need to use a different index instead of j, and save j to be sqrt(-1). I use i for the imaginary variable and for that reason I never write for loops that use the index i.