How do i correct this error, "subscript indices must either be real positive integers or logicals"?
2 次查看(过去 30 天)
显示 更早的评论
This is my code so far...
theta = 10:0.5:80
Function_x(theta) = 981./cosd(theta)
Function_y(theta) = 981./sind(theta)
Function_total(theta) = sqrt(Function_x.^2 + Function_y.^2)
The error is in line 2, but it will happen for all three since they are all defined as the same variable. How do i fix this. The problem asks for the x and y pieces of tension at angle theta, which is between 10 and 80 degrees at a 0.5 degree increments. But i dont know how to fix the error about subscript indices must be real positive integers or logicals. Any help would be fantastic.
0 个评论
采纳的回答
Geoff Hayes
2015-3-4
Jess - you have correctly initialized theta according to the problem but you do not have to use it on the left side of the assignment (and leads to the above error when you try to since theta contains many values that are not integers). If you want Function_x to be a vector of elements that depend upon theta then just initialize this variable as
Function_x = 981./cosd(theta);
The same would be true for Function_y and Function_total. (I'm a little unclear on the naming of all three variables so you may want to rename them to something that more appropriate to their purpose.)
Try the above and see what happens!
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!