Matlab changes XAXIS order

18 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Axis Labels 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by