Calculating the average value of some variables during each sample time
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Iman Hajizadeh
am 27 Mär. 2015
Kommentiert: Andrei Bobrov
am 27 Mär. 2015
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.000’ X1 Y1 Z1;
‘29/07/2014 08:05:00.000’ X2 Y2 Z2;
‘29/07/2014 08:10:00.000’ X3 Y3 Z3;
‘29/07/2014 08:15:00.000’ X4 Y4 Z4;
‘29/07/2014 08:20:00.000’ X5 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?
0 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 27 Mär. 2015
Bearbeitet: Andrei Bobrov
am 27 Mär. 2015
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!