Info

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

Subscript indices must either be real positive integers or logicals

1 次查看(过去 30 天)
When I run this script:
x=-3:.1:3;
Go=1000;
Bc=5;
Pin=@(x) 3*exp(-x.^2);
Ein(i)=quadgk(Pin,-inf,inf);
for i=1:length(x);
z=x(i);
Eo(i)=quadgk(Pin,-inf,z);
E(i)=Eo (i)/Ein(i);
G(i)=Go/(Go-(Go-1)*exp(-E(i)*0.1));
Pin=3*exp(-x(i)^2);
Pout(i)=Pin*G(i);
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*')
I faced this error:
Subscript indices must either be real positive integers or logicals
Please help me on that
  1 个评论
Walter Roberson
Walter Roberson 2011-12-12
It would help if you told us which line the problem is occurring on.
Note: you assign to Poutf(i) after the "for i" loop, and you do not have any other assignments to Poutf. Why do you make that subscripted assignment ?

回答(1 个)

Andrei Bobrov
Andrei Bobrov 2011-12-12
try this is cod
x=-3:.1:3;
Go=1000;
Bc=5;
Pin=@(x)3*exp(-x.^2);
Ein = quadgk(Pin,-inf,inf);
Aout = zeros(size(x));
for i1=1:length(x);
z=x(i1);
E1=quadgk(Pin,-inf,z)/Ein;
G=Go/(Go-(Go-1)*exp(-E1*0.1));
Pout=Pin(z)*G;
Phi=-0.5*Bc*log(G)*pi/180;
Aout(i1)=sqrt(Pout)*exp(1i*Phi);
end
Aoutf=fftshift(fft(Aout,100000));
f = (-100000/2:(100000/2-1)).*1/(0.01*100000);
Poutf = abs (Aoutf).^2;
plot(f,abs(Poutf),'-r*')

此问题已关闭。

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by