Error: Array indices must be positive integers or logical values

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

The code you posted runs fine with no errors.
In general see the FAQ:
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);
3.1027e+03
disp(oForVmax);
60.5900
disp(Vmin);
2455
disp(oForVmin);
0

1 commentaire

You might want to clear all your variables before you execute the script.

Connectez-vous pour commenter.

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);
3.1027e+03
disp(oForVmax);
60.5900
disp(Vmin);
2455
disp(oForVmin);
0

Catégories

En savoir plus sur Aerospace Blockset dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by