Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: interp1 issue
Date: Thu, 13 Nov 2008 11:44:02 +0000 (UTC)
Organization: UTSA
Lines: 45
Message-ID: <gfh3u2$ol1$1@fred.mathworks.com>
References: <gfghdh$405$1@fred.mathworks.com> <gfh057$fbt$1@fred.mathworks.com>
Reply-To: <HIDDEN>
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 1226576642 25249 172.30.248.37 (13 Nov 2008 11:44:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 13 Nov 2008 11:44:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1332985
Xref: news.mathworks.com comp.soft-sys.matlab:500595


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?  

"Titus" <titus.edelhofer@mathworks.de> wrote in message <gfh057$fbt$1@fred.mathworks.com>...
> 
> "Ning" <ning.robin@gmail.com> schrieb im Newsbeitrag 
> news:gfghdh$405$1@fred.mathworks.com...
> > For the example in matlab help 'interp1',
> > t = 1900:10:1990;
> > p = [75.995  91.972  105.711  123.203  131.669...
> >     150.697  179.323  203.212  226.505  249.633];
> > year=1975;
> > interp1(t,p,year)
> > 'ans =214.8585'
> >
> > What if the t is a 3-d matrix (2x3x10), p remains constant, and year is a 
> > 2-d matrix (2x3), the answer would be a 2-d matrix (2x3) with various p 
> > values. How to do this in matlab?
> 
> 
> Hi,
> as long as your data are not too large, I guess the simplest approach would 
> be a loop here:
> 
> res = zeros(size(year));
> for i=1:size(res,1)
>   for j=1:size(res,2)
>     res(i,j) = interp1(t(i,j,:), p, year(i,j));
>   end
> end
> 
> Although: interesting, the t changes but the values are the same? How come?
> 
> Titus 
>