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)
댓글 수: 0
답변 (2개)
James Tursa
2016년 11월 22일
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
Deen Halis
2016년 11월 22일
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
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!