Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: interp1 issue
Date: Thu, 13 Nov 2008 12:32:01 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 28
Message-ID: <gfh6o1$po0$1@fred.mathworks.com>
References: <gfghdh$405$1@fred.mathworks.com> <gfh057$fbt$1@fred.mathworks.com> <gfh3u2$ol1$1@fred.mathworks.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1226579521 26368 172.30.248.35 (13 Nov 2008 12:32:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 13 Nov 2008 12:32:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:500599


"Ning" <ning.robin@gmail.com> wrote in message <gfh3u2$ol1$1@fred.mathworks.com>...
> Thank you, Titus. Here's the for loop code. 
> t = randn(2,3,5);
> p = [10:10:50]; 
> year=randn(2,3);
> for row=1:2
>     for col=1:3
>         out(row,col)=interp1(squeeze(t(row,col,:)), p,year(row,col),'linear','extrap')
>     end
> end
> But I can't use the for loop, since the 't' may be lare, like randn(600,500,5).
> Any idea about this without loop?  

Sorry, but you need a loop if the t variable varies.

Some things are not easily vectorizable. This is one
of them, unless you choose to rewrite interp1. The
real problem lies in the use of histc to efficiently
assign your points into bins for the interpolation.
If the third dimension of t is small for your problem,
it would be possible to write that part to be efficient
without the use of histc. For that to work, t must be
monotonic in the third dimension, which it is not in
your random data.

John