plotting x axis with matched array numbers.

조회 수: 2 (최근 30일)
sermet
sermet 2017년 1월 12일
답변: Walter Roberson 2017년 1월 12일
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
Walter Roberson
Walter Roberson 2017년 1월 12일
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.
sermet
sermet 2017년 1월 12일
R2015a

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

채택된 답변

Walter Roberson
Walter Roberson 2017년 1월 12일
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개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by