Why am I unable to plot all values in a for loop?

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)

回答 (2 件)

James Tursa
James Tursa 2016 年 11 月 22 日

0 投票

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));
Deen Halis
Deen Halis 2016 年 11 月 22 日

0 投票

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)

この質問は閉じられています。

タグ

質問済み:

2016 年 11 月 22 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by