Filter löschen
Filter löschen

Why is the line of y2 always a flat line at x-axis instead of a straight line with negative gradient?

1 Ansicht (letzte 30 Tage)
x = linspace(0, 20, 100);
y1 = (exp(x)-1)/10;
y2 = -x+3;
plot(x, y1, 'r');
hold on;
plot(x, y2, 'g');
xlabel('Diode Voltage');
ylabel('Diode Current');
title('Plot of I_D and V_D');

Akzeptierte Antwort

Image Analyst
Image Analyst am 10 Okt. 2023
It's flat because of hte scale of your y axis. Look -- it goes from -1 to 50 million, while y2 goes from 3 to -17. How do you expect the line to look when it only changes height of 20 in a scale of 50 million?
If you want to see y2, plot it on a separate axes.
  3 Kommentare
Image Analyst
Image Analyst am 11 Okt. 2023
If this Answer solves your original question, then could you please click the "Accept this answer" link to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 10 Okt. 2023
x = linspace(0, 20, 100);
y1 = (exp(x)-1)/10;
y2 = -x+3;
%plot(x, y1, 'r');
hold on;
plot(x, y2, 'g');
xlabel('Diode Voltage');
ylabel('Diode Current');
title('Plot of I_D and V_D');
Which is to say that your y1 goes up to about 5 x 10^7. If we were to guess that the plot is about 500 pixels high then that would mean that there would be 5e7/5e2 = 1e5 data units per pixel. Your y2 covers about 20 data units, so on the scale of 0 to 5*10^7 it occupies about 20/1e5 = 0.0002 pixels of y difference. Which is not enough to be visible.
  1 Kommentar
Rubayet
Rubayet am 10 Okt. 2023
Thanks a lot for your explanation. I did not see the highest value of y-axis and hence could not analyse it before. It worked out now using the function ylim.
Wish you a good day!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by