I get this error message for this code: Array indices must be positive integers or logical values.
4 次查看(过去 30 天)
显示 更早的评论
% Values of constants
l = 89;
h = 49;
D = 55;
beta1 = 11.5;
alpha = 33;
% Compute A, B, C, E
A = l*sind(Beta1);
B = l*cosd(Beta1);
C = (h+0.5*D)*sind(beta1) - 0.5*D*tand(beta1);
E = (h+0.5*D)*cosd(beta1) - 0.5*D;
sindalpha = sind(beta1);
cosddalpha = cosd(beta1);
% output
output = A*sindalpha*cosdalpha + B*sindalpha^2 - C*cosdalpha - E*sindalpha;
disp ('Part a)')
fprintf('%f\n',output);
0 个评论
采纳的回答
Rik
2020-5-18
Check if you have shadowed any function with a variable. Simply by running your code in a clean workspace I found some typos. The code below runs without issue.
In debugging situations like this, check if using clear at the start of your code helps. If it does your errors are due to old variables in your workspace.
% Values of constants
l = 89;
h = 49;
D = 55;
beta1 = 11.5;
alpha = 33;
% Compute A, B, C, E
A = l*sind(beta1);
B = l*cosd(beta1);
C = (h+0.5*D)*sind(beta1) - 0.5*D*tand(beta1);
E = (h+0.5*D)*cosd(beta1) - 0.5*D;
sindalpha = sind(beta1);
cosdalpha = cosd(beta1);
% output
output = A*sindalpha*cosdalpha + B*sindalpha^2 - C*cosdalpha - E*sindalpha;
disp ('Part a)')
fprintf('%f\n',output);
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!