How to set x axis limit while using semilogx

68 ビュー (過去 30 日間)
feit feit
feit feit 2022 年 10 月 17 日
コメント済み: the cyclist 2022 年 10 月 17 日
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]
T = 1×5
0 10 100 1000 10000
Y = [0 1 4 7 10]
Y = 1×5
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

採用された回答

VBBV
VBBV 2022 年 10 月 17 日
編集済み: VBBV 2022 年 10 月 17 日
T1 = [1 10 100 1000 10000] % x values
T1 = 1×5
1 10 100 1000 10000
T2 = [0.1 10 100 1000 10000] % x values
T2 = 1×5
1.0e+04 * 0.0000 0.0010 0.0100 0.1000 1.0000
Y = [0 1 4 7 10]
Y = 1×5
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
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
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 件のコメント
feit feit
feit feit 2022 年 10 月 17 日
Thank you. But, for 10^0, the value of Y is 0 which is not visible in the graph. Here, the graph still starts from 10^1 and there is a discunituity between 10^0 and 10^1. Would you please suggest how to fix it?
the cyclist
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)
ans = -Inf

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by