Why does matlab scale x-axis automatically

3 ビュー (過去 30 日間)
Wonjoon Seol
Wonjoon Seol 2018 年 11 月 2 日
コメント済み: Steven Lord 2018 年 11 月 2 日
Hello,
Why does Matlab scale x axis automatically when it is a decimal number?
For example,
plot(sin([0:0.01:2*pi]))
This graph is not what I asked to plot! The x-axis starts from 0 to 700, when it should be 0 to 7.
At least the x-axis should have shown that it is *10^-2, but it doesn't.
This is misleading, sin(100) isn't 0.8415!
why does MatLab scale all decimal places automatically like this?
And how do I make Matlab to show correct x-axis?
  1 件のコメント
Adam
Adam 2018 年 11 月 2 日
編集済み: Adam 2018 年 11 月 2 日
It is exactly what you asked it to plot, you just didn't ask it what you thought you had! There is no auto-scaling going on.

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

採用された回答

Adam
Adam 2018 年 11 月 2 日
編集済み: Adam 2018 年 11 月 2 日
plot( x, y )
plots the values you want on the x axis.
plot( y )
as you have done just defaults to using indices along the x axis so there are 600 and whatever elements in your array and you get that many elements in x in your plot.
doc plot
explains the syntax.
x = 0:0.01:2*pi;
y = sin( x );
plot(x, y)
should work fine by simply telling it what you want to plot as x and what you want to plot as y.
  1 件のコメント
Steven Lord
Steven Lord 2018 年 11 月 2 日
Adam is correct. There's no scaling of X coordinates taking place. The specific syntax in the Description section of the plot documentation page that covers this case is:
plot(Y) creates a 2-D line plot of the data in Y versus the index of each value.
  • If Y is a vector, then the x-axis scale ranges from 1 to length(Y).
Call plot with two inputs, as Adam showed.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by