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 ループをスキップして、これをすべて 1 つのステップで行う方がよいでしょう。

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 に答える