<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239162</link>
    <title>MATLAB Central Newsreader - interp1 issue</title>
    <description>Feed for thread: interp1 issue</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 13 Nov 2008 06:28:02 -0500</pubDate>
      <title>interp1 issue</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239162#610638</link>
      <author>Ning </author>
      <description>For the example in matlab help 'interp1', &lt;br&gt;
t = 1900:10:1990;&lt;br&gt;
p = [75.995  91.972  105.711  123.203  131.669...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;150.697  179.323  203.212  226.505  249.633]; &lt;br&gt;
year=1975;&lt;br&gt;
interp1(t,p,year)&lt;br&gt;
'ans =214.8585'&lt;br&gt;
&lt;br&gt;
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? </description>
    </item>
    <item>
      <pubDate>Thu, 13 Nov 2008 10:39:34 -0500</pubDate>
      <title>Re: interp1 issue</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239162#610661</link>
      <author>Titus</author>
      <description>&lt;br&gt;
&quot;Ning&quot; &amp;lt;ning.robin@gmail.com&amp;gt; schrieb im Newsbeitrag &lt;br&gt;
news:gfghdh$405$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; For the example in matlab help 'interp1',&lt;br&gt;
&amp;gt; t = 1900:10:1990;&lt;br&gt;
&amp;gt; p = [75.995  91.972  105.711  123.203  131.669...&lt;br&gt;
&amp;gt;     150.697  179.323  203.212  226.505  249.633];&lt;br&gt;
&amp;gt; year=1975;&lt;br&gt;
&amp;gt; interp1(t,p,year)&lt;br&gt;
&amp;gt; 'ans =214.8585'&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; What if the t is a 3-d matrix (2x3x10), p remains constant, and year is a &lt;br&gt;
&amp;gt; 2-d matrix (2x3), the answer would be a 2-d matrix (2x3) with various p &lt;br&gt;
&amp;gt; values. How to do this in matlab?&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Hi,&lt;br&gt;
as long as your data are not too large, I guess the simplest approach would &lt;br&gt;
be a loop here:&lt;br&gt;
&lt;br&gt;
res = zeros(size(year));&lt;br&gt;
for i=1:size(res,1)&lt;br&gt;
&amp;nbsp;&amp;nbsp;for j=1:size(res,2)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;res(i,j) = interp1(t(i,j,:), p, year(i,j));&lt;br&gt;
&amp;nbsp;&amp;nbsp;end&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
Although: interesting, the t changes but the values are the same? How come?&lt;br&gt;
&lt;br&gt;
Titus </description>
    </item>
    <item>
      <pubDate>Thu, 13 Nov 2008 11:44:02 -0500</pubDate>
      <title>Re: interp1 issue</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239162#610671</link>
      <author>Ning </author>
      <description>Thank you, Titus. Here's the for loop code. &lt;br&gt;
t = randn(2,3,5);&lt;br&gt;
p = [10:10:50]; &lt;br&gt;
year=randn(2,3);&lt;br&gt;
for row=1:2&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for col=1:3&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;out(row,col)=interp1(squeeze(t(row,col,:)), p,year(row,col),'linear','extrap')&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
end&lt;br&gt;
But I can't use the for loop, since the 't' may be lare, like randn(600,500,5).&lt;br&gt;
Any idea about this without loop?  &lt;br&gt;
&lt;br&gt;
&quot;Titus&quot; &amp;lt;titus.edelhofer@mathworks.de&amp;gt; wrote in message &amp;lt;gfh057$fbt$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &quot;Ning&quot; &amp;lt;ning.robin@gmail.com&amp;gt; schrieb im Newsbeitrag &lt;br&gt;
&amp;gt; news:gfghdh$405$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; &amp;gt; For the example in matlab help 'interp1',&lt;br&gt;
&amp;gt; &amp;gt; t = 1900:10:1990;&lt;br&gt;
&amp;gt; &amp;gt; p = [75.995  91.972  105.711  123.203  131.669...&lt;br&gt;
&amp;gt; &amp;gt;     150.697  179.323  203.212  226.505  249.633];&lt;br&gt;
&amp;gt; &amp;gt; year=1975;&lt;br&gt;
&amp;gt; &amp;gt; interp1(t,p,year)&lt;br&gt;
&amp;gt; &amp;gt; 'ans =214.8585'&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; What if the t is a 3-d matrix (2x3x10), p remains constant, and year is a &lt;br&gt;
&amp;gt; &amp;gt; 2-d matrix (2x3), the answer would be a 2-d matrix (2x3) with various p &lt;br&gt;
&amp;gt; &amp;gt; values. How to do this in matlab?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; as long as your data are not too large, I guess the simplest approach would &lt;br&gt;
&amp;gt; be a loop here:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; res = zeros(size(year));&lt;br&gt;
&amp;gt; for i=1:size(res,1)&lt;br&gt;
&amp;gt;   for j=1:size(res,2)&lt;br&gt;
&amp;gt;     res(i,j) = interp1(t(i,j,:), p, year(i,j));&lt;br&gt;
&amp;gt;   end&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Although: interesting, the t changes but the values are the same? How come?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Titus &lt;br&gt;
&amp;gt; </description>
    </item>
    <item>
      <pubDate>Thu, 13 Nov 2008 12:32:01 -0500</pubDate>
      <title>Re: interp1 issue</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239162#610675</link>
      <author>John D'Errico</author>
      <description>&quot;Ning&quot; &amp;lt;ning.robin@gmail.com&amp;gt; wrote in message &amp;lt;gfh3u2$ol1$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Thank you, Titus. Here's the for loop code. &lt;br&gt;
&amp;gt; t = randn(2,3,5);&lt;br&gt;
&amp;gt; p = [10:10:50]; &lt;br&gt;
&amp;gt; year=randn(2,3);&lt;br&gt;
&amp;gt; for row=1:2&lt;br&gt;
&amp;gt;     for col=1:3&lt;br&gt;
&amp;gt;         out(row,col)=interp1(squeeze(t(row,col,:)), p,year(row,col),'linear','extrap')&lt;br&gt;
&amp;gt;     end&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; But I can't use the for loop, since the 't' may be lare, like randn(600,500,5).&lt;br&gt;
&amp;gt; Any idea about this without loop?  &lt;br&gt;
&lt;br&gt;
Sorry, but you need a loop if the t variable varies.&lt;br&gt;
&lt;br&gt;
Some things are not easily vectorizable. This is one&lt;br&gt;
of them, unless you choose to rewrite interp1. The&lt;br&gt;
real problem lies in the use of histc to efficiently&lt;br&gt;
assign your points into bins for the interpolation.&lt;br&gt;
If the third dimension of t is small for your problem,&lt;br&gt;
it would be possible to write that part to be efficient&lt;br&gt;
without the use of histc. For that to work, t must be&lt;br&gt;
monotonic in the third dimension, which it is not in&lt;br&gt;
your random data.&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
  </channel>
</rss>

