Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

How do I correct an error about matrix dimensions. The error appears in line 10.

4 Ansichten (letzte 30 Tage)
Dismas hoge
Dismas hoge am 1 Apr. 2017
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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 Kommentare
Rik
Rik am 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
Image Analyst am 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.

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by