MATLAB Answers

LB
0

Help needed: empty plot when plotting for loop

Asked by LB
on 17 Sep 2019 at 23:05
Latest activity Commented on by LB
on 18 Sep 2019 at 3:03
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)

  0 Comments

Sign in to comment.

Products


Release

R2019a

1 Answer

Answer by Walter Roberson
on 17 Sep 2019 at 23:54
 Accepted Answer

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

  2 Comments

LB
on 18 Sep 2019 at 1:13
That worked!! Thank you so much!!
LB
on 18 Sep 2019 at 3:03
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

Sign in to comment.