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

1 次查看(过去 30 天)
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');

采纳的回答

Image Analyst
Image Analyst 2023-10-10
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 个评论
Image Analyst
Image Analyst 2023-10-11
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.

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2023-10-10
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 个评论
Rubayet
Rubayet 2023-10-10
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!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by