bugGNU Octave - Bugs: bug #51728, del2 fails on 1-D input with a...


bug #51728: del2 fails on 1-D input with a vector as spacing

Submitted by:  None
Submitted on:  Fri 11 Aug 2017 11:04:56 AM UTC  
Category: Octave FunctionSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Unexpected Error
Status: Need InfoAssigned to: None
Originator Name: Roger JeurissenOriginator Email: -unavailable-
Open/Closed: OpenRelease: 4.0.0
Operating System: GNU/Linux

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Thu 17 Aug 2017 12:22:54 PM UTC, comment #4:

The code snippet that I gave didn't come out as I expected. Here's a new attempt:

Roger Jeurissen <rogerjeurissen>
Thu 17 Aug 2017 12:19:39 PM UTC, comment #3:

The Matlab documentation for del2 is indeed incorrect here. I said that the example code that I gave works in Matlab, because it came directly from the example on the Mathworks website. I assume that they checked their examples. I don't have access to Matlab right now.

Your suggestion of supplying a spacing for the y-direction is actually much simpler than what I proposed. I assumed that that wouldn't work because the doc says:

At least 3 data points are needed for each dimension.

This solution relies on what happens when there are fewer than 3 data points; that dimension is ignored, so it works. This could be implemented by adding this right after line 80 ( which is h = varargin{1}; )

I just noticed that circshift has the same issue.

Roger Jeurissen <rogerjeurissen>
Fri 11 Aug 2017 05:08:23 PM UTC, comment #2:

Probably easiest to start a session and execute 'diary on'. At the end of the session upload the diary file to the bug report?

Sample Code #1:

Does this produce an error because the spacing is neither a scalar nor a vector?

Sample Code #2:

Documentation says the first spacing applies to the first dimension. However, the first dimension is rows, not columns, which is different than specifying the x-separation which people think of as the first argument.

Sample Code #3:

Just making sure they don't something special for the 1-D vectors in Code #2.

Rik <rik5>
Project Administrator
Fri 11 Aug 2017 04:22:47 PM UTC, comment #1:

Certainly Octave should be able to calculate this.

I think the issue is that Matlab defaults unspecified dimensions to a spacing of 1, despite the fact that the documentation says

For reference, see http://www.mathworks.com/help/matlab/ref/del2.html.

In Octave, the simple way to get this to work is to specify all dimensions. In the Matlab language everything has a minimum of two dimensions. 1-D objects, vectors, are really just Nx1 or 1XN matrices. I can get your code to work simply by supplying a spacing for the Y dimension.


The m-file del2 hasn't been reviewed for a long time and probably needs an overhaul. Given that you have access to Matlab, can you run a few sample pieces of code through Matlab and report the result?

Rik <rik5>
Project Administrator
Fri 11 Aug 2017 11:04:56 AM UTC, original submission:

According to the documentation, the discrete Laplacian of a 1-D array can be calculated with del2, with non-uniform spacing. When I tried to use this, octave threw an error:

error: del2: dimensionality mismatch in 1-th spacing vector

The following code reproduces the error:

In Matlab, this does return a value without errors.

I suspect that this originates from line 73 of del2. There, ndims is used to obtain the number of dimensions of the input array, and this value is stored in the variable nd. However, ndims returns 2 for a 1-D array. What is needed is the number of non-singleton dimensions:

However, this would break the functionality later on, because the for loops run over the dimensions. To fix that, we can add the following lines after line 73:

We should also add this line at the end:

As far as I can see right now, this should work. I tested this fix to check that it solves the issue that i encountered, and it does.



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

Attach File(s):

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by rogerjeurissen (Posted a comment)
  • -unavailable- added by rik5 (Posted a comment)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Tue 15 Aug 2017 06:05:46 AM UTCrik5StatusConfirmed=>Need Info
    Fri 11 Aug 2017 04:22:47 PM UTCrik5StatusNone=>Confirmed

    Back to the top

    Powered by Savane 3.1-cleanup1