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.

 Akzeptierte Antwort

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 Kommentar

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (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

Kategorien

Mehr zu Aerospace Blockset finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by