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.

 채택된 답변

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

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

댓글을 달려면 로그인하십시오.

추가 답변 (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

카테고리

도움말 센터File Exchange에서 Aerospace Blockset에 대해 자세히 알아보기

태그

질문:

2022년 10월 12일

댓글:

2022년 10월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by