채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 10월 6일
편집: Andrei Bobrov 2014년 10월 6일
Let data - your array first column - 'year', second - 'month' ... fifth - 'temp'
[de, ~,c] = unique(data(:,1:2),'rows');
out2 = accumarray(c,data(:,5),[],@(x){[mean(x),min(x),max(x)]});
out = [de, cat(1,out2{:})];
for your array from seattle_tdry.txt only:
f = fopen('seattle_tdry.txt'); c = textscan(f,'%f %f %f %f'); fclose(f);
out2 = accumarray(c{1},c{4},[],@(x){[mean(x),min(x),max(x)]});
out = [unique(c{1}), cat(1,out2{:})];

댓글 수: 1

Asked by Tom:
...
From the weather file I need to work out the monthly average minimum and maximum temperatures. Taking the minimum daily values to get a minimum monthly average, and taking the maximum daily values to get a maximum monthly average.
...
My answer:
f = fopen('seattle_tdry.txt');
c = textscan(f,repmat('%f ',1,4),'collectoutput',1);
fclose(f);
[v1,~,cdaily] = unique(c{:}(:,1:2),'rows');
d1 = accumarray(cdaily,c{:}(:,end),[],@(x){[min(x), max(x)]});
d2 = cat(1,d1{:});
[x,y] = ndgrid(v1(:,1),1:2);
out = [unique(x(:,1)),accumarray([x(:),y(:)],d2(:),[],@mean)];

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

추가 답변 (0개)

카테고리

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

태그

아직 태그를 입력하지 않았습니다.

질문:

Tom
2014년 10월 6일

편집:

Tom
2014년 10월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by