Info

此问题已关闭。 请重新打开它进行编辑或回答。

In an assignment A(I) = B, the number of elements in B and I must be the same.

1 次查看(过去 30 天)
Hi everyone, Here is the code, that gives me the error that I put in my title. Please correct my code, Also, I am new in MATLAB, so if you see better way to do my work, please advice me Thanks in advance
syms t
x=-3:.1:3;
for i=1:length(x);
Pin=3*exp(-t^2);
z=x(i);
Eo(i)=int(Pin,t,-inf,z);
Ein(i)=int(Pin,t,-inf,inf);
E(i)=double(Eo (i)/Ein(i));
Go=1000;
G(i)=Go/(Go-(Go-1)*exp(-E(i)*0.1));
Pin=3*exp(-x(i)^2);
Pout(i)=Pin*G(i);
Bc=5;
Phi(i)=-0.5*Bc*log(G(i))*pi/180;
Aout(i)=sqrt(Pout(i))*exp(i*Phi(i));
end
Aoutf=fftshift(fft(Aout,100000));
f=(-100000/2:(100000/2-1)).*1/(0.01*100000);
Poutf(i)=abs (Aoutf).^2;
plot(f,abs(Poutf),'-r*')

回答(1 个)

Paulo Silva
Paulo Silva 2011-12-8
syms t
x=-3:.1:3;
for i=1:length(x);
Pin=3*exp(-t^2);
z=x(i);
Eo(i)=int(Pin,t,-inf,z);
Ein(i)=int(Pin,t,-inf,inf);
E(i)=double(Eo (i)/Ein(i));
Go=1000;
G(i)=Go/(Go-(Go-1)*exp(-E(i)*0.1));
Pin=3*exp(-x(i)^2);
Pout(i)=Pin*G(i);
Bc=5;
Phi(i)=-0.5*Bc*log(G(i))*pi/180;
Aout(i)=sqrt(Pout(i))*exp(i*Phi(i));
end
Aoutf=fftshift(fft(Aout,100000));
f=(-100000/2:(100000/2-1)).*1/(0.01*100000);
Poutf=abs (Aoutf).^2; %no (i) needed here
plot(f,abs(Poutf),'-r*')
  1 个评论
Paulo Silva
Paulo Silva 2011-12-8
I don't know if the code is correct, just fixed the error, the line you had with Poutf(i)=abs (Aoutf).^2; was wrong because i in that line is equal to length(x), it's just a value so Poutf(i) can only hold one value and the expression in front of the equal sign returns several values, thus the error you got. Without the (i) that variable Poutf can hold almost whatever you want.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by