How can I create a solid line from the data within a for loop?
4 次查看(过去 30 天)
显示 更早的评论
Hi all,
I want to plot efficiency 'Eff' on the y-axis against current density 'i' on the x-axis. However, because the data is in the for loop I cannot produce a solid line. Can someone please explain how I can fix this?
clear all
close all
clc
%I-U curve
T = 80;
r1 = 4.45153e-5;
r2 = 6.88874e-9;
r = r1 + (r2*T);
s = 0.33824;
d1 = -3.12996e-6;
d2 = 4.47137e-7;
p = 30;
t1 = -0.01539;
t2 = 2.00181/T;
t3 = 15.24178/T^2;
t = t1 + t2 + t3;
U_rev = 1.229;
A = 0.25;
f11 = 478645.74;
f12 = -2953.15;
f21 = 1.03960;
f22 = -0.00104;
for i = 0:0.2:100
U = 1.48/(U_rev + ((r1+d1)+(r2*T)+(d2*p))*(i*50) + (s * log((t*(i*50))+1)));
F = (((i*50)^2)/(f11+(f12*T)+(i*50)^2)*(f21+(f22*T)));
Eff = F*U;
plot(i,Eff,'.'); hold on
end
0 个评论
采纳的回答
更多回答(2 个)
Fangjun Jiang
2022-12-12
编辑:Fangjun Jiang
2022-12-12
Typical way is to store the data in an array and then plot it once.
T=0:0.2:100;
Eff=zeros(size(T));
for k=1:length(T)
i=T(k);
U = 1.48/(U_rev + ((r1+d1)+(r2*T)+(d2*p))*(i*50) + (s * log((t*(i*50))+1)));
F = (((i*50)^2)/(f11+(f12*T)+(i*50)^2)*(f21+(f22*T)));
Eff(k) = F*U;
end
plot(T,Eff)
0 个评论
Steven Lord
2022-12-12
Either use an animatedline object or create the line before the loop starts and add points to its XData and YData properties inside the loop. I'll demonstrate the former technique.
h = animatedline;
axis([0 360 -1 1])
for thepoint = 0:360
addpoints(h, thepoint, sind(thepoint))
pause(0.01)
end
I used pause here but you could also use drawnow.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!