Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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

1 ビュー (過去 30 日間)
Abdulaziz 2011 年 12 月 8 日

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 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 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