bugGNU Octave - Bugs: bug #35860, incorrect interp1 with array first...

 
 

bug #35860: incorrect interp1 with array first argument

Submitter:  None
Submitted:  Fri 16 Mar 2012 06:22:04 AM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  jordigh
Originator Name:  David Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 3.6.1
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 26 Jul 2013 05:02:23 AM UTC, comment #4: 

I fixed this error with the following changeset:

http://hg.savannah.gnu.org/hgweb/octave/rev/c8586e6fc60d

Mike Miller <mtmiller>
Group Member
Fri 16 Mar 2012 10:04:00 PM UTC, comment #3: 

When the first argument is a vector, it must be a column vector in order to make sense at all. Indeed, interp1((0:4)', 2.5) does not give an error.
To make it pass all the tests, I suggest putting in

if isvector(y)
  y=y(:);
end

before the
x=1:size(y,1);
statement. Not pretty, but it gets the job done.

David Nijkerk <davidn>
Fri 16 Mar 2012 12:10:03 PM UTC, comment #2: 

Perhaps "length (y)" instead of "numel (y)", but I'm not certain.

Jordi GutiƩrrez Hermoso <jordigh>
Group Member
Fri 16 Mar 2012 12:07:26 PM UTC, comment #1: 

Thanks for reporting.

Your proposed change breaks one of the existing tests:


octave:1> test interp1
  ***** assert (interp1 (0:4, 2.5), 1.5)
!!!!! test failed
interp1: table too short
shared variables
  scalar structure containing the fields:

    xp =

        0    2    4    6    8   10

    yp =

       0.00000   0.58779  -0.95106   0.95106  -0.58779  -0.00000

    xi =

     Columns 1 through 6:

       -1.00000    0.00000    2.20000    4.00000    6.60000   10.00000

     Column 7:

       11.00000

    style = *spline


Do you have a suggestion?

Jordi GutiƩrrez Hermoso <jordigh>
Group Member
Fri 16 Mar 2012 06:22:04 AM UTC, original submission:  

Using interp1 in the following way
YI = interp1 (Y, XI)
with the default, linear interpolation,
gives an error when Y is an array (with more than one dimension).

Example:
========
octave:2> data=rand(3,2)
data =

   0.69133   0.95758
   0.34407   0.70075
   0.23343   0.35873

octave:3> interp1(data,[1 2 3])
error: interp1: quotient: nonconformant arguments (op1 is 2x2, op2 is 5x2)
error: evaluating argument list element number 1
error: called from:
error:   C:\Octave\Octave3.6.1_gcc4.6.2\share\octave\3.6.1\m\general\interp1.m at line 213, column 11
=========
End of example.

I suppose there is an error in the interp1.m script,

  if (isempty (xi) && firstnumeric && ! ispp)
    xi = y;
    y = x;
    x = 1:numel(y);
  endif

should actually read

  if (isempty (xi) && firstnumeric && ! ispp)
    xi = y;
    y = x;
    x = 1:size(y,1);
  endif

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by davidn (Posted a comment)
  • -email is unavailable- added by jordigh (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-07-26 mtmiller StatusIn Progress Fixed
        Open/ClosedOpen Closed
        Operating SystemMicrosoft Windows Any
    2012-03-16 jordigh Assigned toNone jordigh
    2012-03-16 jordigh StatusNone In Progress

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code