Path: news.mathworks.com!not-for-mail
From: "us " <us@neurol.unizh.ch>
Newsgroups: comp.soft-sys.matlab
Subject: Re: vectorizing interp2 for use in 3D arrays?
Date: Tue, 14 Aug 2007 17:58:15 +0000 (UTC)
Organization: Universit&#228;tsSpital Z&#252;rich
Lines: 51
Message-ID: <f9sqfn$rpb$1@fred.mathworks.com>
References: <f93kfr$ppb$1@fred.mathworks.com> <f9sdak$oci$1@fred.mathworks.com>
Reply-To: "us " <us@neurol.unizh.ch>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1187114295 28459 172.30.248.37 (14 Aug 2007 17:58:15 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 14 Aug 2007 17:58:15 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 11
Xref: news.mathworks.com comp.soft-sys.matlab:423912


Aurelien Stalder:
<SNIP down to good point...

> interp2 and interp3 are not doing the same job and will 
not give you exactly the same results...

correct - albeit, down to FP minutes...
however, the problem is timing, as one can see running the 
snippet below, which yields this on a
wintel system (p5/1.3g/512m/win2k.sp4/r2007a)

Elapsed time is 0.304378 seconds. <- loop
Elapsed time is 0.649021 seconds. <- 3d
     -0.46836       10.816       11.284 <- loop
     -0.46836       10.816       11.284 <- 3d
 -3.5527e-015  3.5527e-015  7.1054e-015 <- loop-3d

just a thought
us

% the data
     nr=10;
     nc=25;
     nz=50;
     m=10*rand(nr,nc,nz);
     x=1:nc;
     y=1:nr;
     z=1:nz;
     xi=1:.5:nc;
     yi=1:.5:nr;
     zi=ones(size(z));
% the loop
tic
     m1=zeros(numel(yi),numel(xi),numel(zi));
for  i=z
     m1(:,:,i)=interp2(x,y.',m(:,:,1),xi,yi.','cubic');
end
toc
% the 3d
tic
     m2=interp3(x,y.',z,m,xi,yi.',zi,'cubic');
toc
% the result
% - equal within FP accuracy...
     r=m1-m2;
     disp([
          [min(m1(:)),max(m1(:)),range(m1(:))]
          [min(m2(:)),max(m2(:)),range(m2(:))]
          [min(r(:)),max(r(:)),range(r(:))]
     ]);