Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 1 (최근 30일)
Abdulaziz
Abdulaziz 2011년 12월 8일
마감: MATLAB Answer Bot 2021년 8월 20일
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