App Designer: Plotting on uiaxes from a callback. Formatting X-axis as HH:mm:ss
Show older comments
I have arrays of accelerometer sensor data which have been recorded at 10Hz. The array "time" contains time data as a sequence of seconds with 0.1s resolution: {1.1,1.2,1.3,1.4...etc}. I can plot my acceleration variables (Ax, Ay,Az) on the Y-axis against the X-axis timebase in seconds without a problem.
properties (Access = private)
time
Ax
Ay
Az
The data recordings are usually around 8 hrs long and I would like to format the x-axis in HH:mm.
After reading several helpful comments here, I supposed that app.graph_plot.XTickFormat = 'HH:mm'; but it doesn't work (the code jumps to the "catch" error handler). The only thing which I can get to slightly work is with "datetick".. however MATLAB gives me a warning that it is better to use "xtickformat".
app.CNS_plot = uifigure("Name",'Acceleration Plot','Color','white');
app.graph_plot = uiaxes(app.CNS_plot,'YLimMode','auto','YLim',[-inf,inf]);
app.graph_plot.Toolbar.Visible = 'on';
app.graph_plot.XAxis.Exponent = 0;
app.graph_plot.TickDir = 'out';
datetick(app.graph_plot,'x','HH:mm'); {Matlab warns me that this is not recommended}
app.graph_plot.XLabel.String = 'Time in Seconds';
When the figure is created, the X-axis is formatted as 00:00, 06:00, 12:00, 18:00 so it seems to work, however when I plot the data using
plot(app.graph_plot, app.time, app.Ax,"Color",'black','LineStyle','-','DisplayName','Accel X');
then all formatting disappears. Now I suppose that the issue could be with my "time" array definition. It is not explicitely defined as a 'datetime' or a 'duration' array. I am sure this must be a common problem, and all the answers I have seen so far (using XTickFormat) won't run.
Can anyone please suggest a solution?
many thanks
Accepted Answer
More Answers (0)
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!