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.

 採用された回答

Image Analyst
Image Analyst 2022 年 10 月 12 日
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 件のコメント

David Hill
David Hill 2022 年 10 月 12 日
You might want to clear all your variables before you execute the script.

サインインしてコメントする。

その他の回答 (1 件)

David Hill
David Hill 2022 年 10 月 12 日
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 ExchangeAerospace 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