Why do I get "Array indices must be positive integers or logical values" error?

3 次查看(过去 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?

回答(2 个)

Arif Hoq
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)
Vc = 1×25
1.0e-04 * -0.1782 -0.1614 -0.1220 -0.0783 -0.0518 -0.0384 -0.0107 0.0362 0.0710 0.0868 0.1066 0.1463 0.1909 0.2132 0.2268 0.2592 0.3043 0.3381 0.3521 0.3732 0.4169 0.4576 0.4786 0.4937 0.5271

Askic V
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)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by