FIND on a 0x0 returns a 0x1

John W. Eaton jwe at octave.org
Wed Mar 25 12:05:03 CDT 2009


On 25-Mar-2009, Carsten Clark wrote:

| --------
| Bug report for Octave 3.0.3 configured for i686-pc-cygwin
| 
| Description:
| -----------
| 
|   * When FIND is called on a 0x0 matrix, it returns a 0x1
|     empty matrix.  This is inconvenient because a FOR loop
|     will be entered when given a 0x1 empty matrix to
|     iterate over.
| 
|     For reference, FIND in MATLAB R2007b returns a 0x0
|     empty matrix in the same situation, and a FOR loop
|     over the result is not entered.
| 
|     My vote would be that it would make more sense for FIND
|     to return a 0x0 when given a 0x0.  However, on some other
|     inputs, both Octave's and MATLAB's FIND functions will
|     return a 0x1, which a FOR loop will enter.  So perhaps
|     the proper behavior is up for debate, and I should change
|     my code ;-)
| 
| Repeat-By:
| ---------
| 
| Here are trivial and a practical examples in Octave and MATLAB:
| 
| (In Octave 3.0.3)
| 
| $ octave -qf
| octave:1> find ( [] )
| ans = [](0x1)
| octave:2> for c = find ( [] ), c, end
| c = [](0x1)
| 
| $ octave -qf
| octave:1> tracks = repmat ( struct ('active', 0), 1, 0 );
| octave:2> w = [tracks.active]
| w = [](0x0)
| octave:3> for inx = find(w), inx, end
| inx = [](0x1)
| 
| 
| (In MATLAB R2007b)
| 
| >> find ( [] )
| ans =
|      []
| >> size(ans)
| ans =
|      0     0
| >> for c = find ( [] ), c, end
| >>
| 
| >> tracks = repmat ( struct ('active', 0), 1, 0 );
| >> w = [tracks.active]
| w =
|      []
| >> size(w)
| ans =
|      0     0
| >> for inx = find(w), inx, end
| >>

I don't see a problem with catching matrices that have all dimensions
zero and returning [] in those cases.  But I'm not sure about other
cases where one (or more) of the dimensions of the empty matrix is not
zero.

What does Matlab do for the following?

  find (zeros (0, 0))
  find (zeros (1, 0))
  find (zeros (0, 1))

  find (zeros (0, 0, 0))
  find (zeros (1, 0, 0))
  find (zeros (0, 1, 0))
  find (zeros (1, 1, 0))
  find (zeros (0, 0, 1))
  find (zeros (1, 0, 1))
  find (zeros (0, 1, 1))

Is it consistent in some way?

jwe


More information about the Bug-octave mailing list