フィルターのクリア

Array indices must be positive integers or logical values.

43 ビュー (過去 30 日間)
Jocelyn
Jocelyn 2020 年 11 月 13 日
コメント済み: Steven Lord 2023 年 8 月 31 日
Hello,
My code below is displaying the following error message:
"Array indices must be positive integers or logical values.
Error in Assign5_Prob7 (line 38)
phi(i) = atand(tan(phi_o)+((g*t(i))/Vx_o)*((1/3)*((Vx_o/Vx(i)+ sqrt((Vx_o/Vx(i)))+1)))); "
I don't see anything resulting in a zero within the equation. I'm not sure why this error is displaying. Thank you.
Vy_o = 0.00001;
Vx_o = 2296;
phi_o = atand(Vx_o/Vy_o);
for i = 1:6
x(i) = (i-1)*200*3;
y(i) = (i-1)*200*3;
Vx(i) = (sqrt(Vx_o) - ((k3/2)*x(i)))^2;
t(i) = (x(i)/Vx_o)*sqrt(Vx_o/Vx(i));
phi(i) = atand(tan(phi_o)+((g*t(i))/Vx_o)*((1/3)*((Vx_o/Vx(i)+ sqrt((Vx_o/Vx(i)))+1))));

採用された回答

Cris LaPierre
Cris LaPierre 2020 年 11 月 13 日
This error means that your index variable i is either
  • negative
  • zero
  • not an integer
Check your code that you did not include and see if you modify the value of i somewhere before getting to line 38.
  3 件のコメント
Jocelyn
Jocelyn 2020 年 11 月 13 日
I think the error has something to do with the line directly beneath line 38 (which is the phi(i) =... line).
When I took out the tan(i) = line, the phi(i) = line worked and a table was produced.
Once I put the tan(i) = line back into the code, I got the same message as I posted before:
" Array indices must be positive integers or logical values.
Error in Assign5_Prob7 (line 38)
phi(i) = atand(tan(phi_o)+((g*t(i))/Vx_o)*((1/3)*((Vx_o/Vx(i)+ sqrt((Vx_o/Vx(i)))+1))));
Do you have any thoughts as to why this is happening?
phi(i) = atand(tan(phi_o)+((g*t(i))/Vx_o)*((1/3)*((Vx_o/Vx(i)+ sqrt((Vx_o/Vx(i)))+1)))); % firing angle
tan(i)= tan(phi(i))-((g*t(i))/Vx_o)*((1/3)*((Vx_o/Vx(i)+ sqrt((Vx_o/Vx(i)))+1))); % impact angle
end
T = table(x(:)/3, x(:), Vx(:), t(:), phi(:), tan(:), 'VariableNames',{'yards', 'feet', 'striking velocity', 'time of flight', 'firing angle', 'impact angle'})
Cris LaPierre
Cris LaPierre 2020 年 11 月 13 日
編集済み: Cris LaPierre 2020 年 11 月 13 日
The line below 38 will not cause an error to appear in line 38.
Try sharing all 38 lines of your code, rather than just the one or two around the error. If you want, you can attach your script using the paperclip icon.

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

その他の回答 (1 件)

Varun Krishna
Varun Krishna 2023 年 8 月 31 日
t=0:0.01:2;
x(t)=3.*sin(10.*pi.*t).*exp(-2.*t);
  1 件のコメント
Steven Lord
Steven Lord 2023 年 8 月 31 日
There's no such thing as element 0 or element 0.01 of an array in MATLAB. Replace x(t) with just x. Or if you want to create a function that can be evaluated for different values of t, make x an anonymous function.
t=0:0.01:2;
x=3.*sin(10.*pi.*t).*exp(-2.*t);
y = @(t) 3.*sin(10.*pi.*t).*exp(-2.*t);
isequal(x, y(t)) % evaluate y at the points in t
ans = logical
1

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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by