t(j) is coming up as an error when trying to graph values. what am i doing wrong

2 ビュー (過去 30 日間)
Ennis Winters IV
Ennis Winters IV 2019 年 11 月 13 日
編集済み: Star Strider 2019 年 11 月 13 日
for i= 0:0.1:t1
t(j)=i;
h(j)=v*t(j)*sin(theta)-((g*t(j)*t(j))/2);
x(j)=v*t(j)*cos(theta);
j=(j+i);
end

採用された回答

Star Strider
Star Strider 2019 年 11 月 13 日
編集済み: Star Strider 2019 年 11 月 13 日
It doesn’t appear that you have defined ‘j’ anywhere before the loop.
One possibility:
iv = 0:0.1:t1;
for j = 1:numel(iv)
t(j)=iv(j);
h(j)=v*t(j)*sin(theta)-((g*t(j)*t(j))/2);
x(j)=v*t(j)*cos(theta);
jv(j)=(j+iv(j));
end
  2 件のコメント
Ennis Winters IV
Ennis Winters IV 2019 年 11 月 13 日
sorry I forgot about that part i had
j=1; above the for loop.
Star Strider
Star Strider 2019 年 11 月 13 日
The problem then is that you are adding ‘i’ to ‘j’. However, the elements of ‘i’ need to be integers, since MATLAB subscript references are defined as integers greater than zero.
I have edited my code creating ‘jv’ so that ‘j’ are only integers.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by