I get this error message for this code: Array indices must be positive integers or logical values.

1 Ansicht (letzte 30 Tage)
% 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);

Akzeptierte Antwort

Rik
Rik am 18 Mai 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);

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by