plotting x axis with matched array numbers.
4 views (last 30 days)
time_array=[3 23 30;3 23 45;4 0 0;4 0 15;4 0 30;4 0 45;4 1 0;4 1 15;4 1 30;4 1 45;4 2 0;4 2 15;4 2 30];
time_format=duration(time_array,'Format','hh:mm:ss'); % days:hour:minute
when I plot the data, how can I show only time_format numbers on the x-axis instead of other intervening numbers?
Walter Roberson on 12 Jan 2017
When you use a datetime or duration object for an axes, the default tick labels depend upon the size of your axes. You are seeing ticks every 5 minutes; if your window were narrower you would see them every 10 minutes.
You have asked to show only the times in duration_format . Unfortunately those times are bunched close together in two different places with a relatively large gap between the places. You probably will not be able to make your axes window wide enough to be able to see the separate ticks labeled. But if you want to try then proceed as follows:
This information is for R2015a only and will not work without changes in any other release.
After your plot, do
ax = gca;
xrule = ax.XRuler; %this part is specific to R2015a, in R2015b it become XAxis
xrule.TickLabelRotation = 90;
xrule.Tick = days(time_format); %this part is specific to earlier HG2, in later HG2 the ticks became duration objects directly
Unfortunately if you resize the axes, then the ticks will be automatically chosen again and you would need to assign to Tick again. I think that might have been an R2015a bug.