Fri 25 Aug 2017 11:29:33 PM UTC, comment #8:
I fixed this on the development branch. See cset http://hg.savannah.gnu.org/hgweb/octave/rev/c7b801f36be4. Since this is just an mfile, the original reporter (OP) can grab the file del2.m from the Octave Mercurial repository to get the fix.
The OP also mentioned a problem with circshift. Please file a new bug report about that with an example of the problem.

Fri 25 Aug 2017 06:11:51 AM UTC, comment #7:
Never mind. I found a bug in the code. I don't need the test in comment #6 to be run.

Fri 25 Aug 2017 05:31:31 AM UTC, comment #6:
I've recoded the input validation, but I need another test run. What does Matlab do for this code

Thu 24 Aug 2017 09:23:31 AM UTC, comment #5:
On Matlab R2017a:

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:

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 ydirection 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.

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 xseparation which people think of as the first argument.
Sample Code #3:
Just making sure they don't something special for the 1D vectors in Code #2.

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. 1D 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.
Sample:
The mfile 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?

Fri 11 Aug 2017 11:04:56 AM UTC, original submission:
According to the documentation, the discrete Laplacian of a 1D array can be calculated with del2, with nonuniform spacing. When I tried to use this, octave threw an error:
error: del2: dimensionality mismatch in 1th 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 1D array. What is needed is the number of nonsingleton 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.
