Why do I get "Array indices must be positive integers or logical values" error?
1 次查看(过去 30 天)
显示 更早的评论
lc= 0.03
b=0.013
Rc= 0.0275
theta1= 0:15:360
theta2=theta1*pi/180
x=lc/2;
y=((Rc^2)*(theta2))
z=((b^2)*0.5)*(sin((theta1).*2))
r=b*(sin(theta1))
u1=Rc^2
u2=r.^2
u=r.*(((u1)-(u2)).^1/2)
rr=Rc^2*atan(r/u)
Vc=x(y+z-u-rr)
Why can't solve? Can someone help me?
0 个评论
回答(2 个)
Arif Hoq
2023-1-30
try this:
lc= 0.03;
b=0.013;
Rc= 0.0275;
theta1= 0:15:360;
theta2=theta1*pi/180;
x=lc/2;
y=((Rc^2)*(theta2));
z=((b^2)*0.5)*(sin((theta1).*2));
r=b*(sin(theta1));
u1=Rc^2;
u2=r.^2;
u=r.*(((u1)-(u2)).^1/2);
rr=Rc^2*atan(r/u);
Vc=x*(y+z-u-rr)
0 个评论
Askic V
2023-1-30
You asked why, and the answer is because of this line:
Vc=x(y+z-u-rr)
here, x is considered an array and y+z-u-rr is an index. basically you're trying to access an element of the array throught its index. Indices should be positive integers or logical values and not numbers with decimal points.
So this is probably a typo and Arif corrected this line to be:
Vc=x*(y+z-u-rr)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!