MATLAB: Issue with XTicks and XTickLabels in App Designer

app designerxtick

I have a plot in app designer that uses a UI Axis. The data goes to 32 hours but I would like to limit the x axis (Time in hours) range to 24 hours and then label the XTicks every 4 hours. However, with the XLim working to limit to 24 hours, the distance between Ticks is still 5 hours, but with the correct Tick Labels. Am I missing something?
Capture.JPG
This is my axis manipulation code:
app.UIAxes2.XAxisLocation = 'origin';
app.UIAxes2.YAxisLocation = 'origin';
app.UIAxes2.XMinorGrid = 'on';
app.UIAxes2.YMinorGrid = 'on';
app.UIAxes2.XGrid = 'on';
app.UIAxes2.YGrid = 'on';
app.UIAxes2.XLimMode = 'manual';
app.UIAxes2.XLim = [0 24];
app.UIAxes2.XTickMode = 'manual';
app.UIAxes2.XTick = ([0 4 8 12 16 20 24]);
app.UIAxes2.XTickLabelMode = 'manual';
app.UIAxes2.XTickLabel = [0 4 8 12 16 20 24];
app.UIAxes2.YLimMode = 'auto';
app.UIAxes2.YTickMode = 'auto';

Best Answer

Your code is fine. I think you're assuming the tick interval is 5 hours because there are 5 minor grid lines in each interval. If that's the case, you shouldn't assume the minor ticks are at 1-hr intervals.
Below is an example in the documentation where the minor grids contain 5 segments between ticks. To be certain that your ticks are correct, plot some data at known coordinates and make sure they align with your ticks.
plot(4,1,'r*') % on tick x=4
190501 091200-DisplayMajorMinorGridLinesExample_01.png (560×420).jpg