[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: colon equivalence when deleting elements

**From**: |
pkienzle |

**Subject**: |
Re: colon equivalence when deleting elements |

**Date**: |
Fri, 17 Oct 2003 06:17:05 +0100 |

On 13 Oct 2003 at 11:00, John W. Eaton wrote:
>* There is a current thread in comp.soft-sys.matlab about the subtleties*
>* of indexing when deleting elements of a matrix. For example, in*
>* Matlab,*
>* *
>* a = 1; a(:,:) = []*
>* *
>* results in a 0x1 empty matrix. This doesn't make much sense to me,*
>* but apparently it is working one dimension at a time or something.*
Consider
a = [1 2; 3 4; 5 6];
a(1:2,:) = [] results in a 1x2 matrix, so by extension
a(1:3,:) should be 0x2, which it is.
Similarly, a(:,1) = [] results in a 3x1 matrix, so by extension
a(:,1:2) should be 3x0, which it is.
The a(:,:) = [] case is ambiguous and IMHO should be
disallowed.
>* Also, the following*
>* *
>* a = 1; a(1,1) = []*
>
>* is not allowed ("Indexed empty matrix assignment is not allowed).*
>* Apparently at least one of the indices must be a colon.*
For an N-d array, N-1 of the dimensions must be a colon
so that the entire slice is removed. If not then you would get
surprising results, such as a(i,j) = [] deleting all of row i and
all of column j.
>* Octave currently checks to see if the index is equivalent to a colon*
>* operator (i.e., it enumerates all possible indices) and if so, works*
>* the same as if a colon had been used.*
I think it is better to be consistent in this case and either disallow
it or do the surprising thing regardless of whether or not i and j
happen to span their entire dimension.
>* Should Octave be changed to be exactly compatible for these cases?*
I would disallow both and see if it becomes a problem in
the future. I don't think it will since (a) I don't expect it to
occur often and (b) when it occurs the program does not
silently give a different answer.
Paul Kienzle
address@hidden