Fri 29 Apr 2016 02:46:18 AM UTC, comment #7:
Lachlan, yes I'm suggesting closing this Won't Fix, we haven't yet seen a viable example showing where this would be useful to emulate. The argument to ind2sub is supposed to be the size of an array, so how would that be an empty array?
|
Fri 15 Apr 2016 06:12:18 PM UTC, comment #6:
The user may not call ind2sub with a [] matrix (willingly), but it may happen in case a lot of operations are being performed (failure of user to pass the parameters correctly while scripting/ inability of user to foresee this kind of problem with data while writing the script). I think we could simply give the user a warning (upon execution) that this operation can cause a problem in computations because it is not a logically correct operation (and not because Octave cannot do it ).
MATLAB trial using 2^30 gives:
>> [ii, jj, kk] = ind2sub ([1, 1, 2^30], [3 4; 5 6])
ii =
1 1
1 1
jj =
1 1
1 1
kk =
3 4
5 6
|
Wed 13 Apr 2016 12:49:35 AM UTC, comment #5:
Aditya, if x = [], which is size [0,0], there is no reason to expect that ind2sub ([], ...) will generate indices that can index it.
Note also that your example used "sizem" where Mike suggested "sizemax" (which seems not to be supported in Matlab -- try 2^30 instead).
The important question is: can you think of a reason a user may want to call ind2sub with an empty size matrix?
|
Mon 11 Apr 2016 10:50:35 AM UTC, comment #4:
I would like to work on this.
Upon testing the MATLAB outputs:
>> x=[];
>> [i,j] = ind2sub ([], 3)
i =
1
j =
3
I think this output might be wrong.
>> x(3)
Index exceeds matrix dimensions.
>> x(i,j)
Index exceeds matrix dimensions.
Should Octave give the same error "Index exceeds matrix dimensions." for the ind2sub command?
More MATLAB testing gives:
>> [ii, jj, kk] = ind2sub ([1, 1, sizem], [3 4; 5 6])
Error using sizem (line 21)
Not enough input arguments.
>> [i,j] = ind2sub ([0, 0], 3)
i =
NaN
j =
NaN
|
Mon 11 Apr 2016 08:03:26 AM UTC, comment #3:
Mike, are you suggesting closing this with "won't fix"?
Rik, I don't quite follow your example. Your comments after the example seem to apply to
rather than the example you gave. As Mike pointed out, [] is not the size of any valid matrix.
To me, the question is whether or not handling [] in this way may allow a user to avoid a "special case" check in some context. If so, there is value in handling it the way Matlab does.
Unfortunately the original poster didn't leave an email, so we'll never know where this came up.
|
Wed 06 Apr 2016 05:58:46 PM UTC, comment #2:
Judging by the example given for Matlab's behavior, it looks like it is basically interpreting the empty dimension vector something like this (which does work in Octave):
But since everything in Octave has at least 2 dimensions, I don't see what the point of all this is.
|
Wed 06 Apr 2016 03:25:38 PM UTC, comment #1:
I'm not sure we want to follow Matlab in this regard.
Take a simpler example
If they both produce errors then it seems like we should be warning the user as soon as the error condition has been created (the call to ind2sub) rather than when the indexing x(i,j) is later done. Particularly as the calculation of the indices might be done in a subroutine which could be very far removed from their eventual usage in the main code for indexing.
|
Wed 06 Apr 2016 12:45:04 PM UTC, original submission:
The Octave function ind2sub with an empty dimension vector gives an error. In Matlab it returns the value of the second argument.
>> ind2sub([], [3 4; 5 6])
ans =
3 4
5 6
>> [ii,jj,kk] = ind2sub([], [3 4; 5 6])
ii =
1 1
1 1
jj =
1 1
1 1
kk =
3 4
5 6
|