0

好的,这听起来很容易,但无论我尝试了多少次,我仍然无法正确绘制它。我在同一张图上只需要 3 条线,但仍然有问题。

iO = 2.0e-6;
k = 1.38e-23;
q = 1.602e-19;


for temp_f = [75 100 125]
    T = ((5/9)*temp_f-32)+273.15;
        vd = -1.0:0.01:0.6;
        Id = iO*(exp((q*vd)/(k*T))-1);
        plot(vd,Id,'r',vd,Id,'y',vd,Id,'g');
        legend('amps at 75 F', 'amps at 100 F','amps at 125 F');    

end;       

ylabel('Amps');
xlabel('Volts');
title('Current through diode');

现在我知道他们当前的绘图功能不起作用,并且需要设置某种变量,例如 (vd,Id1,'r',vd,Id2,'y',vd,Id3,'g'); 但是我真的无法掌握改变它的概念并正在寻求帮助。

4

1 回答 1

3

您可以使用“保持”功能来使每个绘图命令与上一个绘图命令在同一窗口上绘图。

最好跳过 for 循环,而只需一步完成。

iO = 2.0e-6; 
k = 1.38e-23; 
q = 1.602e-19; 

temp_f = [75 100 125];
T = ((5/9)*temp_f-32)+273.15;

vd = -1.0:0.01:0.6;
% Convert this 1xlength(vd) vector to a 3xlength(vd) vector by copying it down two rows.
vd = repmat(vd,3,1);

% Convert this 1x3 array to a 3x1 array.
T=T';
% and then copy it accross to length(vd) so each row is all the same value from the original T
T=repmat(T,1,length(vd));

%Now we can calculate Id all at once.
Id = iO*(exp((q*vd)./(k*T))-1);

%Then plot each row of the Id matrix as a seperate line. Id(1,:) means 1st row, all columns.
plot(vd,Id(1,:),'r',vd,Id(2,:),'y',vd,Id(3,:),'g');
ylabel('Amps'); 
xlabel('Volts'); 
title('Current through diode');

这应该得到你想要的。

于 2012-04-30T03:57:20.220 回答