Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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');

Risposta accettata

Image Analyst
Image Analyst il 10 Ott 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 Commenti
Image Analyst
Image Analyst il 11 Ott 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.

Accedi per commentare.

Più risposte (1)

Walter Roberson
Walter Roberson il 10 Ott 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 Commento
Rubayet
Rubayet il 10 Ott 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!

Accedi per commentare.

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by