Calculating the average value of some variables during each sample time

Hi, I have data that contains one columns for time and some columns for values of some variables the same as following (this is a part of my data):
A=[ 29/07/2014 08:00:00.000 152 28 2;
29/07/2014 08:00:01.000 100 20 8;
29/07/2014 08:00:02.000 201 45 7;
29/07/2014 08:00:03.000 149 23 6]
First, the start time, finish time and sample time (time interval) are given by user. I want to calculate the average value for each variable during each sample time that user specified. Suppose that user has given the following information: Start time: ‘29/07/2014 08:00:00.000’; Finish time: ‘29/07/2014 08:20:00.000’; Sample time: 5 ;% based on minute. I Finally want to have a set of data as the following:
F=[29/07/2014 08:00:00.000X1 Y1 Z1;
29/07/2014 08:05:00.000X2 Y2 Z2;
29/07/2014 08:10:00.000X3 Y3 Z3;
29/07/2014 08:15:00.000X4 Y4 Z4;
29/07/2014 08:20:00.000X5 Y5 Z5];
That for example X2 is the average of X values between ‘29/07/2014 08:00:00.000’ and ‘29/07/2014 08:05:00.000’ and X3 is the average of X values between ‘29/07/2014 08:05:00.000’ and ‘29/07/2014 08:10:00.000’. Would you please help me how can I do this?

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2015년 3월 27일
편집: Andrei Bobrov 2015년 3월 27일
A={ '29/07/2014 08:00:00.000' 152 28 2;
'29/07/2014 08:08:01.000' 100 20 8;
'29/07/2014 08:12:02.000' 201 45 7;
'29/07/2014 08:13:03.000' 149 23 6
'29/07/2014 08:15:03.000' 149 23 6
'29/07/2014 08:16:03.000' 149 23 6
'29/07/2014 08:18:03.000' 149 23 6}
t2 = datenum(2014,7,29,8,(0:5:20)',0);
t1 = datenum(A(:,1),'dd/mm/yyyy HH:MM:SS.FFF');
[~,ii] = histc(t1,[t2;inf]);
B = cell2mat(A(:,2:end));
s = size(B); % EDIT
[r,c] = ndgrid(ii,1:s(2));
F = [datevec(t2),accumarray([r(:),c(:)],B(:),[numel(t2),s(2)],@mean)];

댓글 수: 2

Dear Andrew, Thank you for your help and time. But in your answer, there is a variable "s" that it has not been defined.
Sorry, my mistake, fixed.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

질문:

2015년 3월 27일

댓글:

2015년 3월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by