how to specify time and months for year long data ?
1 view (last 30 days)
Show older comments
.
Accepted Answer
Andrei Bobrov
on 6 Oct 2014
Edited: Andrei Bobrov
on 6 Oct 2014
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 Comment
Andrei Bobrov
on 7 Oct 2014
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)];
More Answers (0)
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!