How to put only the day number on the X-axis while 24 values being plotted for each day?

2 views (last 30 days)
I have hourly data for each day for a month( size 31x24)and need to plot them in a away only the day number appears on the X-axis for corresponding 24 values being plotted. In other words, X-axis should show only 1,2,3, ...31, for 24 values of each day. Please help me with that.
Thanks.

Answers (1)

dpb
dpb on 23 Jul 2017
Edited: dpb on 24 Jul 2017
Did you convert to datetime as I suggested in the earlier thread? If so, if you have late release (R2016b?) use the ruler format property to set the format that you wish <plot-dates-and-durations>
ADDENDUM OK, see if I did get the interpretation right now or not... :)
Again starting from the previous fixup of the original data in the datetime array...
plot(da,randn(size(da))) % plot against absolute time
% set x-axis limits to beginning of first day, next day after end of data (*)
xlim(datenum(year(da(1)),month(da(1)),[day(da(1)) day(da(end))+1]))
% space ticks on daily interval from first to last of xlim range
dtk=datenum(2010,11,[day(da(1)):day(da(end))+1]);
set(gca,'xtick',dtk)
This yields the following--
Alternatively, if just want the day numbers but not the month label then adding
% set the time format to display numerical days only...
datetick('x','dd','keeplimits','keepticks')
produces
As noted earlier, I've R2014b so the datetime ruler object isn't available, hence the use of datetick. You can use whichever of the tools are in the release you have but the basic idea (I think) should now be clear?
(*) There also likely won't be enough room for 300/24 --> 12+ ticks on a daily basis but try it and see
  3 Comments
dpb
dpb on 23 Jul 2017
Need to see the code and what you think "doesn't work" means, precisely.
I don't understand what you intend by the " first 24 values to be shown as "1" description, sorry.
Do you mean you really only want to plot by days and use some representative value for all the data for each day or as I mentioned before do you want all the points for a given hour of day on top of each other for all the days or something totally different?
I'm sure it'll be pretty simple to generate whatever you want; the problem is figuring out just what that is... :)
dpb
dpb on 23 Jul 2017
AHA! I think it has just dawneth on me...I was fixated on the hours even while the subject line say "days"...see if the updated Answer fixes the problem.

Sign in to comment.

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Tags

No tags entered yet.

Products

Community Treasure Hunt

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

Start Hunting!