"Subscript indices must either be real positive integers or logicals"
1 回表示 (過去 30 日間)
古いコメントを表示
Hi,
I'm not sure if this is the right title, but I ran into a problem with my current code.
speed=[1511 1505.7 1490.2 1484.1 1480.3 1481.8 1485.4 1491 1506.3 1524 1548.6];
depth=[0 85 165 295 665 1005 1505 2005 3005 4005 5000];
phi=20;
i=1;
r=0;
while r<4000
n=1;
xn=1;
for i=1:11
c1=speed(1,i);
z1=depth(1,i);
z2=depth(1,i+1);
c2=speed(1,i+1);
a=sind(phi)/c1;
for z=z1:z2
m=(c2-c1)/(z2-z1);
n=c1-m*z1;
cn=m*z+n;
theta=asind(a*cn);
dx=(z-(z+1))*tand(theta);
xn=xn+dx
x(1,n)=abs(xn);
y(1,n)=z;
n=n+1
r=abs(xn);
end
end
phi=phi+5;
end
However, if I run it, I get the error
Subscript indices must either be real positive integers or logicals.
Error in ATOC (line 83)
x(1,n)=abs(xn);
which I don't understand, because n should be a positive integer...
Any ideas? Thank you very much!
0 件のコメント
採用された回答
Star Strider
2015 年 10 月 31 日
You have two definitions of ‘n’ in your loop, first:
n=c1-m*z1;
then later:
n=n+1;
The first one is creating fractional values for ‘n’, and that is what is throwing the error. It occurs when the lengths of ‘x’ and ‘y’ each have 1511 elements. Since I do not know what you are doing, I cannot offer any specific solution.
2 件のコメント
Star Strider
2015 年 11 月 1 日
Anke Kügler’s ‘Answer’ is copied here:
Haha, that is indeed stupid and quite embarrassing. I totally forgot about the two n's. Thank you, that did solve my problem!
Star Strider
2015 年 11 月 1 日
My pleasure!
The sincerest expression of appreciation here on MATLAB Answers is to Accept the Answer that most closely solves your problem.
その他の回答 (1 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!