以分钟为单位绘制格式时间(分钟秒) [英] Plotting with respect to minutes as formatted time (min.sec)

查看:195
本文介绍了以分钟为单位绘制格式时间(分钟秒)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图以分钟为单位而不是以秒为单位绘制一些数据作为格式化时间,即min.sec.

I'm trying to plot some data with respect to minutes instead of seconds in Matlab as formatted time, i.e. min.sec.

我有实时数据流,每个接收到的样本都在该流中发送,其时间也以秒为单位发送.然后,我根据时间绘制它们.现在,由于我的课程大约需要15分钟,因此我无法根据时间进行绘图.因此,我想针对时间(min.sec)对其进行绘制.我尝试将接收的时间除以60,但这给了我带有100个细分的分钟而不是60(分钟从0.9999而不是0.59递增).如何转换它,以便可以在几分钟内绘制出时间?

I have real time data streaming in where with every sample received, its time in seconds is also sent. I then plot them with respect to time. Now, since my session is around 15 minutes long, I can't be plotting with respect to time. Therefore I wanted to plot it with respect to time (min.sec). I tried dividing the received time by 60 but this gives me minutes with 100 subdivisions instead of 60 (the minutes increment after 0.9999 instead of 0.59). How do I convert it so that I'm able to plot with respect to time in minutes?

这是我的意思是每分钟0.99分而不是0.59.正常的分钟数有60个分区而不是100个.

Here is what I mean by 0.99 fractions of a minute instead of 0.59. A normal minute has 60 divisions not 100.

我尝试了m7913d的建议,这就是我得到的.

I tried m7913d's suggestions and here is what I got.

  1. 首先,我以秒为单位相对于时间绘制信号,而没有改变刻度(正常的plot(t,v))

我在图中添加了datetick('x', 'mm:ss');(Matlab 2015b不支持Xtick格式)

The I added datetick('x', 'mm:ss'); to the plot (Xtick format is not supported in Matlab 2015b)

这是结果的屏幕截图

以秒为单位的时间最多为80秒,如果换算为分钟,则应该给我1分20秒作为x轴的最大限制.但这种情况并非如此.我试图构造一个t向量(例如t=0:seconds(3):minutes(3)),但无法将其链接到我的秒向量,随着从串行端口接收到新样本,秒向量将不断更新. 谢谢

The time in seconds was up to 80 seconds, when translated into minutes, it should give me 1 minutes and 20 seconds as the maximum x axis limit. But this is not the case. I tried to construct a t vector (i.e like t=0:seconds(3):minutes(3)) but I couldn't link it to my seconds vector which will be constantly updating as new samples are received from the serial port. Thanks

推荐答案

您可以使用

You can use xtickformat to specify the desired format of your x labels as follows:

% 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表示为秒.

Note that I used the seconds methods, which returns a duration object, to indicate to Matlab that t is expressed in seconds.

上面脚本的输出是(右图是左图的放大版):

The output of the above script is (the right image is a zoomed version of the left image):

Pre R2016b

可以使用datetime代替xtickformat,如下所示:

One can use datetime instead of xtickformat as follows:

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)])

这篇关于以分钟为单位绘制格式时间(分钟秒)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆