how to set x axis into hours

i have problem . how to i set the x axis into hour. i have 10080 data and each one represents one minute of data. i want to represents x axis with 24 hour, how can I make like that

 채택된 답변

Walter Roberson
Walter Roberson 2012년 6월 15일

1 개 추천

xtickat = 0:60:length(YourData)-1; %every hour from 00:00
set(gca, 'XTick', xtickat, 'XTickLabel', cellstr( num2str( mod(round(xtickat .' ./ 60),24) ) ) )
This will use hour 0, 1, 2, ... 23, 0, 1, 2, ... 23, and so on, with no indication of the day of the week (as the question asked for x axis to be in 24 hour, not for day and hour)
This will try to produce 168 ticks, which might perhaps be too much for your purposes. If so you can increase the 60 in xtickat to a more appropriate number such as 360 (6 hours).

댓글 수: 6

Innosens
Innosens 2012년 6월 15일
thank you very much walter ,if for day and hour how i can make it? i want to this data for 7 days but with axis to be in 24 hours,
Walter Roberson
Walter Roberson 2012년 6월 15일
Could you give an example of what you would like the labels to look like?
Innosens
Innosens 2012년 6월 16일
ok my data represents about for 7 day. 10080 = 7 days , if one day is 1440 data. i want to plot x label with 24 hour may be like this ...
[0 6 12 18 24 6 12 18 24 6 12 18 24 6 12 18 24 6 12 18 24 6 12 18 24 6 1218 24] . how ican make like this in matlab.. thaks before
Walter Roberson
Walter Roberson 2012년 6월 16일
The code above will do that, except that it will use 0 instead of 24. If you want 24, subtract one before doing the mod(), and add 1 to the mod() result. If it is important, then fix the first entry (which will have become 24.)
Innosens
Innosens 2012년 6월 16일
sory i can't understand what do you mean, where i put the subtract one and add one.
Thanks before...
Walter Roberson
Walter Roberson 2012년 6월 16일
mod(round(xtickat .' ./ 60),24)
would become
1 + mod(round(xtickat .' ./ 60) - 1,24)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2012년 6월 15일

0 개 추천

Something along the lines of:
set(gca,'xticklabel',num2cell(num2str((0:2:22)'),2)')

댓글 수: 2

Walter Roberson
Walter Roberson 2012년 6월 15일
Why use num2cell for that?
set(gca, 'xticklabel', cellstr( num2str((0:2:22).') ) )
However, this has the problem that you need exactly the matching number of Xtick values
Sean de Wolski
Sean de Wolski 2012년 6월 15일
CELLSTR is sweet (and new to me!). I'd heard of ISCELLSTR, but not CELLSTR.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File 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