Help needed: empty plot when plotting for loop

Hello,
Below is my code. I am trying to plot all values of the for loop but I am getting an empty plot. What am I doing incorrectly?
for i=2:1:1369
a = (V(i+1)-V(i-1))/(2*(t(i+1)-t(i-1)));
A = ((1/2)*Rhoa*Cd*Af*(V(i).^3));
G = (Mv*g*cos(0).*V(i));
I = (1.1*Mv.*a.*V(i));
Pw = (A+G+I)/1000;
end
figure
hold on
i=2:1:1369;
plot(i,Pw);
grid
xlabel('Time (s)')
ylabel('Power, Pw (KW)')
set(h,'linewidth',2)

 採用された回答

Walter Roberson
Walter Roberson 2019 年 9 月 17 日

1 投票

Do not assign to Pw. Instead assign to Pw(i-1)

2 件のコメント

JD
JD 2019 年 9 月 18 日
That worked!! Thank you so much!!
JD
JD 2019 年 9 月 18 日
Hi Walter,
After being able to plot the graph based on your response to this question, I realized my for loop is not doing what I want. Would you be able to help with the below question as well?
Thanks

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

製品

リリース

R2019a

質問済み:

JD
2019 年 9 月 17 日

コメント済み:

JD
2019 年 9 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by