Matlab changes XAXIS order
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Philip Hoskinson
am 11 Feb. 2016
Beantwortet: Walter Roberson
am 11 Feb. 2016
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.
0 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 11 Feb. 2016
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)
0 Kommentare
Weitere Antworten (1)
Walter Roberson
am 11 Feb. 2016
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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!