2012-04-30 22 views
0

これは簡単ですが、何回試みても、正しくプロットすることはできません。同じグラフ上に3行しか必要ではありませんが、それでも問題はあります。FORループ内に複数の行をプロットするMATLAB

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');しかし、私は本当にそれを変更するという概念を理解することができず、助けを求めています。

答えて

3

"hold on"機能を使用すると、各プロットコマンドが最後と同じウィンドウにプロットされるようにすることができます。

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'); 

あなたが望むものが得られるはずです。

+0

問題はthoです。問題のためにforループを使用する必要がありますが、基本プログラミングでは何も複雑になりません。上記のプロット方法がうまくいくのですか? – user1364968

関連する問題