I get this error message for this code: Array indices must be positive integers or logical values.
1 view (last 30 days)
Show older comments
% 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 Comments
Accepted Answer
Rik
on 18 May 2020
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 Comments
More Answers (0)
See Also
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!