Info
This question is closed. Reopen it to edit or answer.
How do I correct an error about matrix dimensions. The error appears in line 10.
2 views (last 30 days)
Show older comments
m=1;
D=0.5;
lambda=20;
K=(2*pi)/lambda;
z=0:10:1000;
C=2./(m.*pi).*sin(m.*pi.*D);
d=0;
for i=1:length(z)
d=d+C(i)*exp(-1i.*K.*z);
end
g=sign(d);
k=20001;
rect=zeros(1,k);
for n=1:k
if x(n)>0&x(n)<1
rect(n)=1;
elseif x(n)==0||x(n)==1
rect(n)=0.5;
else
rect(n)=0;
end
n=n+1;
end
hz=rect.*g;
re=real(g);
Y=fftshift(fft(g))/length(g);
%plot(z,abs(Y))
plot(z,hz)
%plot(z,g)
2 Comments
Rik
on 1 Apr 2017
d=d+C(i)*exp(-1i.*K.*z); is not a valid syntax, use d=d+C(i)*exp(-1*i.*K.*z); instead. Also, you are calling C(i), but C is only a scalar.
Image Analyst
on 1 Apr 2017
d=d+C(i)*exp(-1i.*K.*z) IS valid syntax. -1i is how you use the imaginary variable i:
>> z=exp(-1i*2)
z =
-0.416146836547142 - 0.909297426825682i
Works fine. Using -1 * i is a totally different operation than using -1i, but they both work.
Answers (0)
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!