您可以使用
xtickformat指定x标签的所需格式,如下所示:
% generate a random signal (in seconds)
t = 0:5:15*60;
y = rand(size(t));
plot(seconds(t),y) % plot your signal, making it explicit that the t is expressed in seconds
xtickformat('mm:ss') % specify the desired format of the x labels
请注意,我使用seconds方法返回一个duration对象,以向Matlab指示t以秒为单位表示.
上述脚本的输出是(右图像是左图像的缩放版本):
前R2016b
可以使用datetime而不是xtickformat,如下所示:
datetimes = datetime(0,0,0,0,0,t); % convert seconds to datetime
plot(datetimes,y)
datetick('x', 'MM:SS'); % set the x tick format (Note that you should now use capital M and S in the format string
xlim([min(datetimes) max(datetimes)])