Average of irregular range of data

I have a time series of satellite data over a bout 6 years. With each pass of the satellite a number of measurements are taken. The number of measurements taken is non-uniform, so anywhere between 2 and 7 for a given pass of the satellite. This occurs every 10 days but there are occasions when the satellite misses a pass. I want to get the average of each pass without having to go through the data and inputting the correct ranges manually. Is there a way of setting a rule so that when the time between two measurements is greater than say a day a new range of data is selected? Any help would be appreciated.

댓글 수: 2

Andrei Bobrov
Andrei Bobrov 2013년 8월 15일
편집: Andrei Bobrov 2013년 8월 15일
short example of your data, please
David
David 2013년 8월 15일
Hi Andrei, here are the first few passes of the satellite, with the figure on the right being the wave height:
09/01/2003 21:05 1.73
09/01/2003 21:05 2.196
09/01/2003 21:05 1.979
19/01/2003 19:03 6.507
19/01/2003 19:03 6.676
29/01/2003 17:02 6.132
29/01/2003 17:02 6.379
29/01/2003 17:02 5.714
08/02/2003 15:00 5.019
08/02/2003 15:00 4.671
08/02/2003 15:00 4.814
08/02/2003 15:00 4.783
08/02/2003 15:00 4.334

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

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 15일
편집: Azzi Abdelmalek 2013년 8월 15일

0 개 추천

data={'09/01/2003 21:05 1.73'
'09/01/2003 21:05 2.196'
'09/01/2003 21:05 1.979'
'19/01/2003 19:03 6.507'
'19/01/2003 19:03 6.676'
'29/01/2003 17:02 6.132'
'29/01/2003 17:02 6.379'
'29/01/2003 17:02 5.714'
'08/02/2003 15:00 5.019'
'08/02/2003 15:00 4.671'
'08/02/2003 15:00 4.814'
'08/02/2003 15:00 4.783'
'08/02/2003 15:00 4.334'}
dates= datenum(data,'dd/mm/yyyy');
weights=cellfun(@(x) str2double(x{3}),regexp(data,'\s+','split'));
[a,b,c]=unique(dates);
average_values=accumarray(c,weights,[],@mean);
out=[cellstr(datestr(dates(b))) num2cell(average_values)]
%or
dates=datenum(data,'dd/mm/yyyy');
s=regexp(data,'\s+','split');
s=[s{:}];
weights=str2double(s(3:3:end))';
[a,b,c]=unique(dates);
average_values=accumarray(c,weights,[],@mean);
out=[cellstr(datestr(dates(b))) num2cell(average_values)];
Andrei Bobrov
Andrei Bobrov 2013년 8월 15일
편집: Andrei Bobrov 2013년 8월 15일

0 개 추천

tresh = 2; % Let greate than two days
f = fopen('PathAndNameYourdata.txt');%'E:\wtdy2.txt'
c = textscan(f,'%s %s %f','CollectOutput',true);
fclose(f);
k = strcat(c{1}(:,1),{' '},c{1}(:,2));
n = datenum(k,'dd/mm/yyyy HH:MM');
ii = [true;diff(n)>tresh];
i1 = cumsum(ii);
i2 = find(ii);
out = [{'start','finish','mean of value'};
[k([i2,[i2(2:end)-1;numel(n)]]), accumarray(i1,c{2},[],@(x){mean(x)})]];

댓글 수: 3

David
David 2013년 8월 15일
Thanks for reply Andrei. I ran this code but the following error message was returned:
Error: File: Mean_swh.m Line: 13 Column: 11 The construct "i3(...end...)" is ambiguous in this context, because "i3" cannot be ascertained to be either the name of a variable or of a function. To make it a variable, assign to it; to allow it to become a function at execution time, replace "end" with a call to LENGTH, SIZE, or NUMEL on the desired array.
David
David 2013년 8월 15일
Just changed it around a little and it works perfectly. Thanks for the help Andrei, much appreciated.
Andrei Bobrov
Andrei Bobrov 2013년 8월 15일
Oh! My typo! Corrected.

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

카테고리

도움말 센터File Exchange에서 Data Preprocessing에 대해 자세히 알아보기

태그

질문:

2013년 8월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by