Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

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

1 visualizzazione (ultimi 30 giorni)
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*')

Risposte (1)

Paulo Silva
Paulo Silva il 8 Dic 2011
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 Commento
Paulo Silva
Paulo Silva il 8 Dic 2011
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.

Questa domanda è chiusa.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by