how to extract time after calculating mean and standard deviation?

1 次查看(过去 30 天)
Hello all of my Matlab friends,
I have a data file of every minute data for one year (from march 1 to December 31) as follows:
Date Time O3 Tb TL Prs
2009-03-01 00:00:00 14.0 25.6 56.8 740.2
2009-03-01 00:01:00 13.9 25.6 56.8 740.2
2009-03-01 00:02:00 13.8 25.6 56.8 740.2
2009-03-01 00:03:00 13.6 25.6 56.8 740.2
2009-03-01 00:04:00 13.4 25.6 56.8 740.2
2009-03-01 00:05:00 13.3 25.6 56.8 740.2
2009-03-01 00:06:00 13.2 25.6 56.8 740.2
2009-03-01 00:07:00 13.4 25.6 56.8 740.2
2009-03-01 00:08:00 13.4 25.6 56.8 740.2
2009-03-01 00:09:00 13.3 25.6 56.8 740.2
2009-03-01 00:10:00 13.4 25.6 56.8 740.3
2009-03-01 00:11:00 13.1 25.6 56.8 740.3
2009-03-01 00:12:00 13.6 25.6 56.8 740.2
2009-03-01 00:13:00 13.7 25.6 56.8 740.2
2009-03-01 00:14:00 13.6 25.5 56.8 740.3
2009-03-01 00:15:00 13.5 25.5 56.8 740.3
2009-03-01 00:16:00 13.3 25.5 56.8 740.3
2009-03-01 00:17:00 13.3 25.5 56.8 740.3
2009-03-01 00:18:00 13.8 25.5 56.8 740.3
2009-03-01 00:19:00 13.8 25.5 56.8 740.3
2009-03-01 00:20:00 14.0 25.5 56.8 740.3
2009-03-01 00:21:00 14.3 25.5 56.8 740.3
2009-03-01 00:22:00 14.2 25.5 56.8 740.3
2009-03-01 00:23:00 14.2 25.4 56.8 740.3
2009-03-01 00:24:00 14.6 25.4 56.8 740.3
2009-03-01 00:25:00 14.4 25.4 56.8 740.4
2009-03-01 00:26:00 14.3 25.4 56.8 740.3
2009-03-01 00:27:00 14.3 25.4 56.8 740.4
2009-03-01 00:28:00 14.0 25.4 56.8 740.4
2009-03-01 00:29:00 14.0 25.4 56.8 740.3
2009-03-01 00:30:00 14.2 25.4 56.8 740.4
2009-03-01 00:31:00 14.3 25.4 56.8 740.4
2009-03-01 00:32:00 14.0 25.4 56.8 740.4
2009-03-01 00:33:00 14.2 25.4 56.8 740.4
2009-03-01 00:34:00 14.3 25.4 56.8 740.4
2009-03-01 00:35:00 14.2 25.4 56.8 740.5
2009-03-01 00:36:00 14.1 25.4 56.8 740.5
2009-03-01 00:37:00 13.8 25.4 56.8 740.4
2009-03-01 00:38:00 14.1 25.4 56.8 740.4
2009-03-01 00:39:00 14.3 25.4 56.8 740.5
2009-03-01 00:40:00 14.0 25.4 56.8 740.4
2009-03-01 00:41:00 14.2 25.4 56.8 740.4
2009-03-01 00:42:00 14.1 25.4 56.8 740.5
2009-03-01 00:43:00 13.9 25.4 56.8 740.5
2009-03-01 00:44:00 13.9 25.4 56.8 740.5
2009-03-01 00:45:00 14.0 25.4 56.8 740.4
2009-03-01 00:46:00 14.1 25.4 56.8 740.5
2009-03-01 00:47:00 13.9 25.4 56.8 740.5
2009-03-01 00:48:00 13.9 25.4 56.8 740.5
2009-03-01 00:49:00 14.0 25.4 56.8 740.5
2009-03-01 00:50:00 13.9 25.5 56.8 740.5
2009-03-01 00:51:00 14.1 25.5 56.8 740.5
2009-03-01 00:52:00 14.0 25.5 56.8 740.5
2009-03-01 00:53:00 14.2 25.5 56.8 740.5
2009-03-01 00:54:00 14.2 25.5 56.8 740.6
2009-03-01 00:55:00 14.0 25.5 56.8 740.6
2009-03-01 00:56:00 14.0 25.5 56.8 740.5
2009-03-01 00:57:00 13.8 25.5 56.8 740.5
2009-03-01 00:58:00 13.7 25.5 56.8 740.5
2009-03-01 00:59:00 13.3 25.5 56.8 740.5
2009-03-01 01:00:00 13.2 25.5 56.8 740.5
2009-03-01 01:01:00 13.3 25.5 56.8 740.5
2009-03-01 01:02:00 13.9 25.5 56.8 740.6
2009-03-01 01:03:00 13.8 25.5 56.8 740.5
2009-03-01 01:04:00 13.6 25.6 56.8 740.5
2009-03-01 01:05:00 13.9 25.6 56.8 740.6
2009-03-01 01:06:00 14.1 25.6 56.8 740.5
2009-03-01 01:07:00 13.9 25.6 56.8 740.6
2009-03-01 01:08:00 14.0 25.6 56.8 740.6
2009-03-01 01:09:00 13.8 25.6 56.8 740.6
2009-03-01 01:10:00 13.8 25.6 56.8 740.6
2009-03-01 01:11:00 14.0 25.6 56.8 740.6
2009-03-01 01:12:00 13.9 25.6 56.8 740.6
2009-03-01 01:13:00 14.0 25.6 56.8 740.6
2009-03-01 01:14:00 14.4 25.6 56.8 740.6
2009-03-01 01:15:00 14.5 25.6 56.8 740.7
2009-03-01 01:16:00 14.2 25.6 56.8 740.6
2009-03-01 01:17:00 14.1 25.6 56.8 740.6
2009-03-01 01:18:00 14.2 25.6 56.8 740.6
2009-03-01 01:19:00 14.3 25.6 56.8 740.6
2009-03-01 01:20:00 14.6 25.6 56.8 740.6
2009-03-01 01:21:00 14.5 25.6 56.8 740.6
2009-03-01 01:22:00 14.3 25.6 56.8 740.6
2009-03-01 01:23:00 14.8 25.6 56.8 740.6
2009-03-01 01:24:00 14.4 25.6 56.8 740.6
2009-03-01 01:25:00 14.6 25.6 56.8 740.6
2009-03-01 01:26:00 14.7 25.6 56.8 740.7
2009-03-01 01:27:00 14.6 25.6 56.8 740.6
2009-03-01 01:28:00 14.6 25.7 56.8 740.6
2009-03-01 01:29:00 14.5 25.7 56.8 740.7
2009-03-01 01:30:00 14.6 25.7 56.8 740.7
2009-03-01 01:31:00 14.6 25.7 56.8 740.7
2009-03-01 01:32:00 14.1 25.7 56.8 740.7
2009-03-01 01:33:00 14.0 25.7 56.8 740.7
2009-03-01 01:34:00 13.9 25.7 56.8 740.7
2009-03-01 01:35:00 13.7 25.7 56.8 740.7
2009-03-01 01:36:00 13.6 25.7 56.8 740.7
2009-03-01 01:37:00 13.4 25.7 56.8 740.6
2009-03-01 01:38:00 13.8 25.7 56.8 740.7
2009-03-01 01:39:00 13.6 25.7 56.8 740.7
2009-03-01 01:40:00 13.9 25.7 56.8 740.7
2009-03-01 01:41:00 14.1 25.7 56.8 740.7
2009-03-01 01:42:00 14.2 25.7 56.8 740.7
2009-03-01 01:43:00 14.2 25.8 56.8 740.7
2009-03-01 01:44:00 14.3 25.8 56.8 740.7
2009-03-01 01:45:00 14.2 25.8 56.8 740.7
2009-03-01 01:46:00 14.5 25.8 56.8 740.8
2009-03-01 01:47:00 14.3 25.8 56.8 740.8
2009-03-01 01:48:00 14.1 25.8 56.8 740.8
2009-03-01 01:49:00 14.3 25.8 56.8 740.8
2009-03-01 01:50:00 14.4 25.8 56.8 740.8
2009-03-01 01:51:00 14.3 25.8 56.8 740.8
2009-03-01 01:52:00 14.5 25.8 56.8 740.8
2009-03-01 01:53:00 14.3 25.8 56.8 740.8
2009-03-01 01:54:00 14.4 25.8 56.8 740.8
2009-03-01 01:55:00 14.7 25.8 56.8 740.8
2009-03-01 01:56:00 14.6 25.8 56.8 740.8
2009-03-01 01:57:00 14.7 25.8 56.8 740.8
2009-03-01 01:58:00 14.1 25.9 56.8 740.8
2009-03-01 01:59:00 14.5 25.9 56.8 740.8
Does any body have any idea how can I get the 1 hour mean and std for the last four parameters and then extracting the first date how can I make a new array to store my results as follows:
Date Time O3(mean) std Tb std TL std Prs std
2009-03-01 00:00:00 14.0 x 25.6 x 56.8 x 740.2 x
2009-03-01 01:00:00 13.2 x 25.5 x 56.8 x 740.5 x
I don't have any idea how can I make the loop for my one year data and how to extract the date and time. As a matlab novice I can just calculate the mean and std and can write them in a new file.
I will highly appreciate any suggestions regarding the aforementioned problem and thank you very much in advance.
  2 个评论
Jan
Jan 2012-9-11
Please add important information inside the question by editing it, not as comment, which will disappear (optically) as soon as three other comments have been posted. Please format your code properly. The samller the example data, the more likely is that users read the question until the end. I think 10 lines are enough.
Md. Moklesur Rahman
Thanks Jan for the suggestions. Sorry for providing a lengthy data. In fact, I provided two hours data to get two mean and std data point in which case every hour is the iteration for each mean and std.

请先登录,再进行评论。

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-9-11
编辑:Andrei Bobrov 2012-9-11
please try this is code (corrected)
f = fopen('yourdata.txt');
c = textscan(f,'%s %s %f %f %f %f','HeaderLines',1,'CollectOutput',1);
fclose(f);
cc = num2cell(c{1},1);
dd = strcat(cc{:});
dv = datevec(dd,'yyyy-mm-ddHH:MM:SS');
[a,b,x] = unique(dv(:,1:4),'rows','first');
[z,y] = ndgrid(x,1:size(c{2},2));
out1 = zeros(size(a,1),size(c{2},2)*2);
out1(:,1:2:end) = accumarray([z(:),y(:)],c{2}(:),[],@mean);
out1(:,2:2:end) = accumarray([z(:),y(:)],c{2}(:),[],@std);
out = [c{1}(b,:),num2cell(out1)];
  3 个评论
Md. Moklesur Rahman
But whenever I tried to write the output using the following command:
dlmwrite('hourly_mean_O3_2009.dat', out, 'delimiter', '')
close all;
It showed the following errors:
??? Error using ==> dlmwrite at 113
The input cell array cannot be converted to a matrix.
Do you have any idea how can I save my output writing a new text file?
Thank you again.

请先登录,再进行评论。

更多回答(1 个)

Jan
Jan 2012-9-11
You overwrite the toolbox function mean() by a local variable of the same name. There should be an MLint warning. The same for std() .
The values of Time and Time_mean_std are overwritten in each iteration. When you want to collect them, use something like Time(i) and Time_mean_std(i). To learn how to make this efficient, search for "pre-allocation" in this forum.

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by