Clear Filters
Clear Filters

Ticks label problem Julian day

3 views (last 30 days)
Emrys
Emrys on 3 Nov 2017
Edited: dpb on 4 Nov 2017
Hi guys, I have a dataset with 4416 numbers. Plotting it on time series in which every numbers corresponds to an hour and it's quite ugly to see ticks every hours and I chose to put ticks every 10 days (240 ticks), Now my problem was, How can i write te corrisponding julian day to the 10th tick? or the twentieth? Imagine that the first tick is the 1 of January and the second the 10th. Can someone help me please?
  1 Comment
Steven Lord
Steven Lord on 3 Nov 2017
Can you show us a small sample of the code you've written to plot the data (so we can see how it behaves) and include a small sample of data so we can try to run that code? Please also indicate what release of MATLAB you're using so we don't recommend solutions that require functionality introduced after the release you're using.

Sign in to comment.

Answers (1)

dpb
dpb on 3 Nov 2017
Edited: dpb on 4 Nov 2017
Convert the numeric values to datetime either as time or duration depending on the meaning. You'll need to pick the appropriate year for the actual calendar date to match for leap year accounting, of course if want that level of detail.
Then plot is datetime -aware so the axes will be in time units and you can fix up the number/style of ticks as desired.
ADDENDUM
My suggestion looks something like--
t=0:4415; % time vector in hours
t=datetime(2017,1,1,t(:),0,0); % convert to datetime for specific year
plot(t,randn(size(t))) % plot using datetime-aware axes by default
xl=xlim; % retrieve default x-axis limits
xl(1)=datenum(datevec(t(1))); % set LH axis start to beginning of data
xlim(xl)
dtk=datenum(2017,[1:7].',1); % compute monthly tick spacings
set(gca,'xtick',dtk) % set tick values to those
The "trick" above is in setting the x-axis limits to match the beginning of the data exactly rather than the default that tries to space uniformly the ticks across the range. I'm still at R2014b which uses the old datenum as the internal axis variable; I believe that has since been updated to be consistent with the datetime class so can set the tick values with the same time array values as the axis itself removing one slight complexity.
With time axes, labels take a lot of real estate so may not be able to place as many ticks as can with pure numeric axes.
I'm not sure just what the timeseries actually does with plot; what little I've looked at it in R2014b it just didn't have any advantage over keeping a straight time vector for what I'd tried it for; perhaps later incarnations are more developed just as datetime continues to evolve...
  1 Comment
Emrys
Emrys on 3 Nov 2017
Sorry Mr/Mrs dpb if i'm not so practical, can you give a code example? I cannot really set the problem

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!