필터 지우기
필터 지우기

How would you upscale gridded data?

조회 수: 5 (최근 30일)
andrew joros
andrew joros 2012년 4월 5일
Hi
I have a 2-d 12km dataset that I would like to convert to 32km gridded resolution. Just wondering how you would approach this? I have written a for loop seen here: http://pastebin.com/6iq97HyR, but it takes way too long to complete(~1.5 weeks)
Thanks
for lo = 20:91
for la = 1:101
tmplat = latsmall(lo,la);
tmplon = lonsmall(lo,la);
f = find(min((latNLDAS(:)-tmplat).^2+(lonNLDAS(:)-tmplon).^2)==((latNLDAS(:)-tmplat).^2+(lonNLDAS(:)-tmplon).^2));
y = floor(f/224)+1;
y = y(1);
x = mod(f,224);
x = x(1);
for yr = 1:15
tic;
for mo = 1:5
fprintf(' lo %d la %d yr %d mo %d \n',lo,la,yr+1994,mo);
for dy=1:31
pptNL(yr,lo,la,mo,dy)= nan;
if (mo == 2 || 5) && (dy==31)
continue;
else
date = [num2str(mo+4) '/' num2str(dy) '/' num2str(1994+yr)];
if (x-2<=0) || (y-2<=0) || (x-2>224) || (y-2>464) ||...,
(x-1<=0) || (y-1<=0) || (x-1>224) || (y-1>464) ||...,
(x-0<=0) || (y-0<=0) || (x-0>224) || (y-0>464) ||...,
(x+1<=0) || (y+1<=0) || (x+1>224) || (y+1>464) ||...,
(x+2<=0) || (y+2<=0) || (x+2>224) || (y+2>464)
continue
else
pptNL(yr,lo,la,mo,dy)= nanmean...,
([PRECIP(x-2,y+2,datevec2doy(datevec(date)))...,
PRECIP(x-2,y+1,datevec2doy(datevec(date)))...,
PRECIP(x-2,y+0,datevec2doy(datevec(date)))...,
PRECIP(x-2,y-1,datevec2doy(datevec(date)))...,
PRECIP(x-2,y-2,datevec2doy(datevec(date)))...,
PRECIP(x-1,y+2,datevec2doy(datevec(date)))...,
PRECIP(x-1,y+1,datevec2doy(datevec(date)))...,
PRECIP(x-1,y+0,datevec2doy(datevec(date)))...,
PRECIP(x-1,y-1,datevec2doy(datevec(date)))...,
PRECIP(x-1,y-2,datevec2doy(datevec(date)))...,
PRECIP(x,y+2,datevec2doy(datevec(date)))...,
PRECIP(x,y+1,datevec2doy(datevec(date)))...,
PRECIP(x,y,datevec2doy(datevec(date)))...,
PRECIP(x,y-1,datevec2doy(datevec(date)))...,
PRECIP(x,y-2,datevec2doy(datevec(date)))...,
PRECIP(x+1,y+2,datevec2doy(datevec(date)))...,
PRECIP(x+1,y+1,datevec2doy(datevec(date)))...,
PRECIP(x+1,y+0,datevec2doy(datevec(date)))...,
PRECIP(x+1,y-1,datevec2doy(datevec(date)))...,
PRECIP(x+1,y-2,datevec2doy(datevec(date)))...,
PRECIP(x+2,y+2,datevec2doy(datevec(date)))...,
PRECIP(x+2,y+1,datevec2doy(datevec(date)))...,
PRECIP(x+2,y+0,datevec2doy(datevec(date)))...,
PRECIP(x+2,y-1,datevec2doy(datevec(date)))...,
PRECIP(x+2,y-2,datevec2doy(datevec(date)))...,
]);
end
end
end
end
end
end
end
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2012년 4월 5일
I added the code, next time please consider formatting it into the post as I did.
Have you tried running the profile on a small data set to identify the bottlenecks?
Preallocating pptNL would help drastically.
Also, as is, contributors cannot help you because you didn't supply some sample inputs to run your code with.
http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
What is latsmall and lonsmall? (function or variable?)

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by