|
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
>
|