필터 지우기
필터 지우기

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 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