Info
This question is closed. Reopen it to edit or answer.
Why am I unable to plot all values in a for loop?
3 views (last 30 days)
Show older comments
Hello, I am having difficulty plotting all values produced in a for loop. The program will only plot the last value, I'm not sure how to make the program not overwrite the previous values. Any help would be appreciated.
Voc_open = 12;
Voc_close = 5.3333;
Rt_open = 15;
Rt_close = 8.3333;
C = 0.01;
for T = 0: 0.01: 0.2
V_1 = Voc_close + (V_0 - Voc_close).*exp((-T./2)./(Rt_close.*C));
end
plot(T,V_1)
0 Comments
Answers (2)
James Tursa
on 22 Nov 2016
Rather than a loop, can you just do this?
T = 0: 0.01: 0.2;
V_1 = Voc_close + (V_0 - Voc_close).*exp((-T./2)./(Rt_close.*C));
0 Comments
Deen Halis
on 22 Nov 2016
Hello Shayne, try this!
Voc_open = 12;
Voc_close = 5.3333;
Rt_open = 15;
Rt_close = 8.3333;
C = 0.01;
V_0 = 0.1;%%this was a missing variable
T1 = 0: 0.01: 0.2;
for i1 = 1:length(T1)
T = T1(i1);
V_1(i1) = Voc_close + (V_0 - Voc_close).*exp((-T./2)./(Rt_close.*C));
end
plot(T1,V_1)
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!