Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Subscript indices must either be real positive integers or logicals ERROR ,can't solve

1 Ansicht (letzte 30 Tage)
rika
rika am 4 Jul. 2012
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
This is part of the simple code I'm using:
for i=1:9
for v=1:21
iter=1;
while dif(i,v)>tol && iter<=maxiter
W(i,v)=((v(1+a1(i,v)))^2+(r(i)*omega*(1-a2(i,v)))^2)^0.5;
phi(i,v)=atand((v(1+a1(i,v)))/(r(i)*omega*(1-a2(i,v))));
alpha(i,v)=theta(i)-phi(i,v);
CL(i,v)= -1.692600E-08*(alpha(i,v))^6 + 1.039717E-06*(alpha(i,v))^5 - 7.753536E-06*(alpha(i,v))^4 - 4.279007E-04*(alpha(i,v))^3 + 1.045968E-03*(alpha(i,v))^2 + 1.344549E-01*(alpha(i,v)) + 5.043533E-01;
CD(i,v)= -5.381629E-08*(alpha(i,v))^5 + 2.272123E-06*(alpha(i,v))^4 - 4.127824E-06*(alpha(i,v))^3 + 2.575254E-05*(alpha(i,v))^2 - 4.366098E-04*(alpha(i,v)) + 1.235974E-02;
Tgrad(i,v)=0.5*density*(W(i,v))^2*N*c(i)*(CL(i,v)*cosd(phi(i,v))-CD(i,v)*sind(phi(i,v)));
a1new(i,v)=(-1+(1+Tgrad(i,v)/(pi*density*r(i)*v^2))^0.5)/2;
Qgrad(i,v)=0.5*density*(W(i,v))^2*N*c(i)*r(i)*(CL(i,v)*sind(phi(i,v))+CD(i,v)*cosd(phi(i,v)));
a2new(i,v)=Qgrad(i,v)/(4*pi*density*(r(i))^3*v*omega*(1+a1new(i,v)));
difa1=abs(a1new(i,v)-a1(i,v));
difa2=abs(a2new(i,v)-a2(i,v));
if difa1>difa2
dif(i,v)=difa1;
else
dif(i,v)=difa2;
end
a1(i,v)=a1new(i,v);
a2(i,v)=a2new(i,v);
iter=iter+1;
end
end
end
The error is: ??? Subscript indices must either be real positive integers or logicals.
Error in ==> flu3try2 at 36 W(i,v)=((v(1+a1(i,v)))^2+(r(i)*omega*(1-a2(i,v)))^2)^0.5;
Why is this happening? I did not have the same error before adding the while loop.

Antworten (2)

AC
AC am 4 Jul. 2012
Hi,
How did you define your dif function?
The error you get means that at some point you are trying to access part of a vector or a matrix that does not exist, e.g. v(0) or v(0.1).
I would try and debug it and take a look at the values of a1 and a2.
Cheers,
AC

Jan
Jan am 4 Jul. 2012
In v(1+a1(i,v)) the index is not a positive integer anymore.
A reliable method to examine such problems:
dbstop if error
Then Matlab stops when the error occurs and you can check the values of the local variables.
  1 Kommentar
AC
AC am 4 Jul. 2012
Hey, now I'm curious: is dif a new name for function diff? When I ran the code, dif was unknown, I assumed it was a user-defined function. Anyway, yes, dbstop is a good friend :)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by