Error: Array indices must be positive integers or logical values
Afficher commentaires plus anciens
Hi! I'm getting a error that says "Array indices must be positive integers or logical values" about "Vmin=min(V) when running the code below:
m=100;
l=5;
k=200;
g=9.82;
o=[0:0.01:90]; %θ
V=0.5*k*l^2*(sind(o)).^2+0.5*m*g*l*cosd(o);
plot(o,V);
title("V(θ)");
xlabel("θ[°]");
ylabel("V[J]");
Vmax=max(V);
indexMax=find(V==Vmax);
oForVmax=o(indexMax(1));
Vmin=min(V);
indexMin=find(V==Vmin);
oForVmin=o(indexMin(1));
disp(Vmax);
disp(oForVmax);
disp(Vmin);
disp(oForVmin);
I don't really understand why because V will not be zero or negative.
Réponse acceptée
Plus de réponses (1)
Runs without error
m=100;
l=5;
k=200;
g=9.82;
o=[0:0.01:90]; %θ
V=0.5*k*l^2*(sind(o)).^2+0.5*m*g*l*cosd(o);
plot(o,V);
title("V(θ)");
xlabel("θ[°]");
ylabel("V[J]");
Vmax=max(V);
indexMax=find(V==Vmax);
oForVmax=o(indexMax(1));
Vmin=min(V);
indexMin=find(V==Vmin);
oForVmin=o(indexMin(1));
disp(Vmax);
disp(oForVmax);
disp(Vmin);
disp(oForVmin);
Catégories
En savoir plus sur Aerospace Blockset dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

