X-axis: Construct with hourly respect

2 次查看(过去 30 天)
HI I'm trying to construct a x-axis with respect to hours. My codes can be seen below but I'm trying to construct an 24-hour on the x-axis that is from 12:00 (today) to 12:00 (tomorrow); that is counting from 12, 13, 14, 15,..., 9, 10, 11, 12. Can you help?
startdate = datenum('12','HH');
enddate = datenum('12','HH');
dt = linspace(startdate,enddate,24);
data = [1,42,5,3,2,6,77,8,3,5,12,5,84,45,23,64,23,74,784,45,74,5,3,2]; %random data
plot(dt,data)
hold on
datetick('x','yyyy','keepticks');

采纳的回答

Walter Roberson
Walter Roberson 2013-1-16
enddate = startdate + 1;
otherwise your start and end date end up being the same.
dt = linspace(startdate, enddate, 25);
Notice the 25 instead of 24.
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 -> 12 entries
00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12 -> 13 entries
total 25, not 24.
and
datetick('x', 'HH')
  1 个评论
Lily
Lily 2013-1-18
Thx for this hint... It's looks so simple when you think of it like this :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by