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

1 回表示 (過去 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);

採用された回答

Rik
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 件)

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by