フィルターのクリア

Matlab changes XAXIS order

13 ビュー (過去 30 日間)
Philip Hoskinson
Philip Hoskinson 2016 年 2 月 11 日
回答済み: Walter Roberson 2016 年 2 月 11 日
I have two simple matrixes: X is time of day in hours:
X[ 6 7 8 9 10 11 12 1 2 3 4 5 ]
Y[ various values...... ]
When I plot, MATLAB rearranges order of axis so x axis is:
[ 1 2 3 4 5 6 etc...}
I need MATLAB to plot in order as shown originally.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 2 月 11 日
x=[ 6 7 8 9 10 11 12 1 2 3 4 5 ]
y=sin(x)
x1=1:numel(x)
plot(x1,y)
set(gca,'xtick',x1,'xticklabel',x)

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 2 月 11 日
cX = unwrap(X*pi/6)*6/pi;
plot(cX, Y);
The unwrap() is a trick to convert the 12-hour based clock times into continuous hour based clock times (so if you had several 12 hour periods the count would just keep increasing.)
You can use tick labels to change the labeling. For example,
X = repmat(1:24,1,3)/2;
cX = unwrap(X*pi/6)*6/pi;
Y = X.^3;
plot(cX, Y)
set(gca, 'XTick', cX(2:2:end), 'XTickLabel', X(2:2:end));
The 2:2:end is to select out only the exact hours out of the particular sample X values that here are by the half hour.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by