Path: news.mathworks.com!newsfeed-00.mathworks.com!NNTP.WPI.EDU!elk.ncren.net!newsflash.concordia.ca!canopus.cc.umanitoba.ca!not-for-mail
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to find vector value via matrix value?
Date: Mon, 21 Jul 2008 20:33:50 +0000 (UTC)
Organization: National Research Council Canada - Conseil national de rechereches Canada
Lines: 49
Message-ID: <g62rre$4f8$1@canopus.cc.umanitoba.ca>
References: <g62lhb$4sn$1@fred.mathworks.com> <g62nns$s4g$1@canopus.cc.umanitoba.ca> <g62q3i$nrm$1@fred.mathworks.com>
NNTP-Posting-Host: origin.ibd.nrc.ca
X-Trace: canopus.cc.umanitoba.ca 1216672430 4584 192.70.172.160 (21 Jul 2008 20:33:50 GMT)
X-Complaints-To: abuse@cc.umanitoba.ca
NNTP-Posting-Date: Mon, 21 Jul 2008 20:33:50 +0000 (UTC)
Originator: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Xref: news.mathworks.com comp.soft-sys.matlab:480771



In article <g62q3i$nrm$1@fred.mathworks.com>,
Bruno Luong <b.luong@fogale.fr> wrote:
>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
>message <g62nns$s4g$1@canopus.cc.umanitoba.ca>...
>The easiest way to deal
>> with this is likely:

>> m1 = m;
>> m1(m1 < min(v(:))) = min(v);
>> m1(m1 > max(v(:))) = max(v);
>> interp1(v,v,m1,'nearest')

>This might be even easier:

>v=unique(v); % precaustion
>mn = interp1(v,v,m,'nearest','extrap')

Hmmm, that does work for 2007a, but it disagrees with
the documented behaviour:

>> help interp1

    YI = INTERP1(X,Y,XI,METHOD,'extrap') uses the specified method for
    extrapolation for any elements of XI outside the interval spanned by X.
    Alternatively, YI = INTERP1(X,Y,XI,METHOD,EXTRAPVAL) replaces
    the values outside of the interval spanned by X with EXTRAPVAL.
    NaN and 0 are often used for EXTRAPVAL.  The default extrapolation
    behavior with four input arguments is 'extrap' for 'spline' and 'pchip'
    and EXTRAPVAL = NaN for the other methods.

On the other hand,

>> doc interp1

    For the 'nearest', 'linear', and 'v5cubic' methods,
    interp1(x,Y,xi,method) returns NaN for any element of xi that
    is outside the interval spanned by x. For all other methods,
    interp1 performs extrapolation for out of range values.

    yi = interp1(x,Y,xi,method,'extrap') uses the specified method
    to perform extrapolation for out of range values.

which is consistent with the result actually observed (although
not as clearly written, in my opinion.)

I'll file a documentation bug.
-- 
  "Do not wait for leaders. Do it alone, person to person."
                                              -- Mother Teresa