Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

What would be the out of Interp1?

  1. Jul 23, 2012 #1
    Hello guys,

    If i run the following command

    y = interp([1:5 4:9], 1:11, 4);

    what would be the output of the same, and what does it mean?
  2. jcsd
  3. Jul 24, 2012 #2

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    Code (Text):
    > y = interp([1:5 4:9], 1:11, 4)
    error: `interp' undefined near line 92 column 5
    error: evaluating assignment expression near line 92, column 3
    ... does not exist in gnu octave. How about interp1()?
    Code (Text):
    > y = interp1([1:5 4:9], 1:11, 4)
    y =  6
    ... which would be the last value calculated for x.
    Put Y=11:-1:1 and it gives you

    Find out what it means from the help file:
    Code (Text):
    > help interp1
    -- Function File: YI = interp1 (X, Y, XI)
         One-dimensional interpolation. Interpolate Y, defined at the
         points X, at the points XI. The sample points X must be strictly
         monotonic. If Y is an array, treat the columns of Y separately.
    ... or hunt down the function m-file.
    ... or just plot Y vs X and see where XI,YI compare.

    Presumably you mean - "how does the interpolation function handle the case where the input vectors do not represent a function?"
  4. Aug 15, 2012 #3
    As mentioned in the help:

    "The sample points X must be strictly monotonic."

    interp1([1:5 4:9], 1:11, 4)

    should give an error because x ([1:5 4:9]) is not strictly monotonic here, it doesn't have distinct values. Isn't it?
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook