How to set x axis limit while using semilogx
조회 수: 42 (최근 30일)
이전 댓글 표시
I am using the following code to plot a graph in which x axis should be in logarithmic scale starting from 10^0 and y axis in linear scale.
T = [0 10 100 1000 10000]
Y = [0 1 4 7 10]
semilogx(T, Y)
axis([0 10000 0 12])
In the output, I am getting the x axis starts from 10^1 instead of 10^0. Would anyone please suggest how to get the desired x axis limit? Thanks
댓글 수: 0
채택된 답변
VBBV
2022년 10월 17일
편집: VBBV
2022년 10월 17일
T1 = [1 10 100 1000 10000] % x values
T2 = [0.1 10 100 1000 10000] % x values
Y = [0 1 4 7 10]
semilogx(T1, Y,T2, Y)
axis([0 10000 0 12])
since the x values begin with 0, and log(0) is undefined it does not appear in graph. change it small positive value
댓글 수: 1
the cyclist
2022년 10월 17일
I would think carefully about changing a zero to a small positive value, just for the sake of getting a graph to work. It may be fine, but it could also be very deceptive.
Also, the graph could potentially look quite different depending on how small you make the small value, which makes the value of the graph questionable.
추가 답변 (1개)
the cyclist
2022년 10월 17일
10^0 is 1 (not 0), so this works ...
T = [0 10 100 1000 10000];
Y = [0 1 4 7 10];
semilogx(T, Y)
axis([1 10000 0 12])
댓글 수: 2
the cyclist
2022년 10월 17일
The problem is not with your axes, and is not that Y==0. The problem is that T==0. You can't plot that point on a log axis, because log10(0) evaluates to -Inf.
log10(0)
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!