I get this error message for this code: Array indices must be positive integers or logical values.
    4 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
% 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 Commenti
Risposta accettata
  Rik
      
      
 il 18 Mag 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 Commenti
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Characters and Strings in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

