MATLAB:对没有循环的时间序列数据求平均吗? [英] MATLAB: Averaging time-series data without loops?

查看:156
本文介绍了MATLAB:对没有循环的时间序列数据求平均吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以30分钟为间隔测量了一些变量.时间戳以datevecdatenum格式提供.我想计算...

I have measured a handful of variables in 30 minute intervals. Time stamps are available in datevec or datenum format. I want to calculate ...

a)...日均值和
b)...时间x的平均值,例如我整个数据集中的平均温度为11:30,平均温度为12:00,等等.

a) ... daily averages and
b) ... average values at time x, e.g. temperature at 11:30, temperature at 12:00, etc. averaged over my whole dataset.

虽然通过循环可以轻松地完成此操作,但我想知道是否存在一种更简单/更方便的方式来处理时间序列,因为这毕竟是一项非常基本的任务?

While this is, more or less, easily done with loops, I wonder if there is an easier / more convenient way to work with time-series, since this is a quite basic task after all?

/edit 1:根据要求:点击我获取示例数据

/edit 1: As per request: click me for sample data

推荐答案

考虑到datevec()输出存储在tvec中,数据存储在x中,与unique(...,'rows')分组并与accumarray()累加:

Considering that datevec() output is stored in tvec and data in x, group with unique(...,'rows') and accumulate with accumarray():

% Group by day
[unDates, ~, subs] = unique(tvec(:,1:3),'rows');

% Accumulate by day
[unDates accumarray(subs, x, [], @mean)]

% Similarly by hour
[unHours, ~, subs] = unique(tvec(:,4:5),'rows');
[unHours accumarray(subs, x, [], @mean)]

这篇关于MATLAB:对没有循环的时间序列数据求平均吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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