0

Okay so this sounds easy but no matter how many times I have tried I still cannot get it to plot correctly. I need only 3 lines on the same graph however still have an issue with it.

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

Now I know the plot function that is currently in their isn't working and that some kind of variable needs setup like (vd,Id1,'r',vd,Id2,'y',vd,Id3,'g'); however I really can't grasp the concept of changing it and am seeking help.

1 Answer 1

3

You can use the "hold on" function to make it so each plot command plots on the same window as the last.

It would be better to skip the for loop and just do this all in one step though.

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

And that should get what you want.

Sign up to request clarification or add additional context in comments.

1 Comment

The issue is tho I have to use a for loop for the problem, still in basic programming nothing to complicated. whould the plotting method shown above work?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.