Path: news.mathworks.com!not-for-mail
From: "Aurelien Stalder" <aurelien.stalder.remove@uniklinik-freiburg.de>
Newsgroups: comp.soft-sys.matlab
Subject: Re: vectorizing interp2 for use in 3D arrays?
Date: Tue, 14 Aug 2007 14:13:40 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 43
Message-ID: <f9sdak$oci$1@fred.mathworks.com>
References: <f93kfr$ppb$1@fred.mathworks.com>
Reply-To: "Aurelien Stalder" <aurelien.stalder.remove@uniklinik-freiburg.de>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1187100820 24978 172.30.248.38 (14 Aug 2007 14:13:40 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 14 Aug 2007 14:13:40 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1080281
Xref: news.mathworks.com comp.soft-sys.matlab:423870


interp2 and interp3 are not doing the same job and will not
give you exactly the same results! You need to figure out if
you need 2D or 3D interpolation. (i.e. Do you need to
interpolate in the 3rd dimension or not?)

It seems that you don't need to interpolate in the 3rd
dimension. So the loop-interp2 combination is probably your
best choice!

However it seems that what you actually want to do is not
only interpolation but regridding. If your regridding ratio
can be a power of 2 you should probably use ZI =
interp2(Z,ntimes) instead of creating your XI, YI with
meshgrid. For my application it is 40% slower to use interp2
with meshgrid instead of "ntimes".


Aurelien


"Lorenzo Garlappi" <lorenzo.garlappi@gmail.com> wrote in
message <f93kfr$ppb$1@fred.mathworks.com>...
> Hi,
> 
> I am trying to see if it is possible to avoid a loop in the
> following problem regarding the use of interp2.
> 
> Suppose Z is an N-by-M-by-K 3D-array
> I want to interpolate each of the K M-by-N 2D-arrays over a
> finer grid.
> The only solution I could think of is to use interp2 on a
> loop over the K dimension as follows: 
> 
> for k=1:K
>      ZI(:,:,k) = interp2(X, Y, Z(:,:,k), XI, YI, '*linear');
> end
> 
> Is there a better and faster alternative?
> 
> Thanks.
> 
> Lorenzo Garlappi