在Matlab中按时间序列绘制数据 [英] Plotting data with time series in matlab

查看:510
本文介绍了在Matlab中按时间序列绘制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从2007年5月1日到2007年5月30日从00:00到23:59:58有一些数据.我想根据数据和时间一起绘制这些数据.如何同时定义日期和时间?因为它有固定的日期和时间.例如

I have some data from 2007/5/1 to 2007/5/30 from 00:00 to 23:59:58. I want to plot these data according to data and time together. How can I define both date and time together? cause it has a regular date and time. For example

2007/5/1 00:00:00       -0.2
2007/5/1 00:00:02       -0.1
2007/5/1 00:00:04       -0.12
.
.
. 
2007/5/31 23:59:58      -0.4

我已经使用过DateTime代码,但是我有固定的时间间隔,而且我不知道如何解决它.

I've been used DateTime code but I have regular time interval and I don't know how to solve it.

推荐答案

以下是使用datetime变量的示例.您需要将数据导入与时间矢量(下面的t)对齐的相应矢量,以便data(i)t(i)的相关数据.

Here is an example for using a datetime variable. You'll need to import your data to a corresponding vector that aligns with the time vector (t below) so that data(i) is the relevant data for t(i).

% create a datetime vector of all instances:
start = datetime('2007/5/1 00:00:00','InputFormat','uuuu/MM/dd HH:mm:ss');
step = duration(seconds(2));
fin = datetime('2007/5/31 23:59:58','InputFormat','uuuu/MM/dd HH:mm:ss');
t = start:step:fin; % a 1339200 elements vector, of all time steps
% some random data:
data = rand(numel(t),1);
% plotting samples 1 to 100:
plot(t(1:100),data(1:100))
xlim([datenum(t(1)) datenum(t(100))])

我在这里使用随机数作为示例,对于如此长的向量,您将看不到任何东西,所以我只画了一部分:

I use here random numbers for the example, and you won't be able to see anything for such a long vector, so I plot only a portion of it:

这篇关于在Matlab中按时间序列绘制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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