Default axes for plot

11 ビュー (過去 30 日間)
Achilles
Achilles 2013 年 8 月 28 日
Hi. According to the Matlab tutorial, when I plot a column vector of doubles (lets call this vector z), the default y-axis created by plot(z) should be of doubles corresponding to the values in my vector. However, when I do this, the y-axis consists only of the integer values at the endpoints of the interval containing my doubles. e.g. if z = (1.12, 5.43, 7.54) (as a column vector, though), the y-axis will list off 1,2,3,...8. How do I change this for each graph? Also, how do I change the default so that the axis lists the corresponding doubles? Thanks.
(Note: I am an absolute beginner with Matlab, so please treat me accordingly.)

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 28 日
編集済み: Azzi Abdelmalek 2013 年 8 月 28 日
x=[0 1 2]
y= [1.12, 5.43, 7.54]
plot(x,y)
set(gca,'ytick',y,'xtick',x)
  2 件のコメント
Achilles
Achilles 2013 年 8 月 28 日
I am told that the "values must be monotonically increasing." The actual set of values I am using this for is not.
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 28 日
set(gca,'ytick',sort(y),'xtick',sort(x))

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


Jan
Jan 2013 年 8 月 28 日
Even doubles with integer values are doubles, because this defines the type of the variable, not the value.
The problem is not clear to me. It is more clear, if you post your code instead of describing, what the code should do. Which values are not sorted?
Perhaps this helps:
x = rand(1, 10);
y = rand(1, 10);
subplot(1,3,1);
plot(x,y);
[xs, index] = sort(x);
ys = y(index);
subplot(1,3,2);
plot(xs,ys);
subplot(1,3,3);
plot(xs,ys);
set(gca, 'XLim', [min(x), max(x)], 'XTick', x);

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by