plotting x axis with matched array numbers.

PDOP=[1.31;1.33;1.26;1.27;1.29;1.30;1.30;1.29;1.25;1.35;1.24;1.25;1.42];
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
figure(1)
plot(time_format,PDOP,'c','LineWidth',1.75)
when I plot the data, how can I show only time_format numbers on the x-axis instead of other intervening numbers?

4 个评论

What do you mean by 'other intervening numbers'? When I run your code I just get time numbers on the x-axis. 03:50 shows up as 03:49:59, but apart from that I don't see anything obviously wrong.
when I run the code, numbers on the x-axis as follows; [03:20:00 03:25:00 03:30:00 03:35:00 03:40:00 03:45:00 03:50:00 03:55:00 04:00:00 04:05:00]
Which MATLAB version are you using? There were relevant changes in recent releases.
In R2016b the only numbers I see on the X axis are in the format you indicate you want.

请先登录,再进行评论。

 采纳的回答

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.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 App Building 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by