Hourly Averaging over 10s Data

4 次查看(过去 30 天)
I have 10 second data in an excel file. I have opened it will xlsread. The first column is the date and time, which I have converted to a datenumber using datenum(). Now I would like to take an hourly average of data using unique() and accumarray(), which I have used before but I had some help so I'm having difficulty modifying my previous code to work with this particular file. I need help doing this. To begin with I'm having the error:
Error using cell/unique (line 85)
Input A must be a cell array of strings.
I know it can be used with doubles, so I'm not sure what the issue is here. Maybe the issue is that these are in cells so maybe I need to convert every cell to an array but that seems like that could be avoided.
I've included my code below. The data is now like
{datanum} {incorrect date that I need to toss out} {25 columns of data} {three column of data which I need to throw out}
filenameexl = ('June2014Neph_Count_SD_Filtered_Trial');
[ndata, text, alldata] = xlsread(filenameexl)
datetime = alldata(:,1);
formatIn = ('mm/dd/yyyy HH:MM:SS AM');
%Calculating first day of the year to subtract
dayone2014 = ('01/01/2014 12:00:00 AM');
P = datenum(dayone2014,formatIn);
PP = datenum(datetime,formatIn);
%final datenumber to be used
datenumberfinal = num2cell(PP-P);
alldata(:,1) = datenumberfinal;
[u,~,ix] = unique(alldata(:,1),'rows');
I need some help here.
  1 个评论
dpb
dpb 2015-2-2
The 'rows' option only works for cells of strings or numeric. You're only wanting the unique values for the column any way so it's superfluous here; drop it.
I'd convert to arrays out of cells on general principles anyway; there's no need of a cell array here once you've converted a datastring to datenumber.

请先登录,再进行评论。

采纳的回答

Chad Greene
Chad Greene 2015-2-2
It's hard to see what exactly is going on because we don't have your source data and your variable names are not intuitive.
If you have an array of data y taken at times t, you can use downsample_ts to get hourly means:
[y_hourly,t_hourly] = downsample_ts(y,t,'hourly','mean');

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by