octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fix null assignment


From: John W. Eaton
Subject: Re: fix null assignment
Date: Thu, 18 Sep 2008 10:36:09 -0400

On 18-Sep-2008, Levente Torok wrote:

| HI Jaroslav,
| 
| Look the example below of Matlab:
| 
| a=[1:5]; a(1:5)=[]
| 
| a =
| 
|   Empty matrix: 1-by-0
| 
| but
| 
|  a=[1:5]; a(:)=[]
| 
| a=
|      []
| 
| Why should a(1:length(a)) be different from a(:) in any circumstances?
| I don't think this is a consequent think.

My guess is: the special syntax '(:)' means all elements and is
trapped early.  There is no check on a range as an index to see
whether it enumerates all elements.  So you might call this an
accident of the implementation that could somehow later be justified
in one way or another (I guess you'd have to ask the MathWorks, or
maybe Cleve, to see what he was thinking).

| Or.
| a' * a
| ans = 
|    0
| 
| a * a'
|    []
| 
| I think this is very much arbitrary think.

No, I think that's consistent behavior.  See for example the two
papers about properties of empty matrices cited in the Octave manual.
BTW, Octave tried to get this right some time before Matlab did.
Originally, Matlab did not carry dimensions for empty arrays.  It only
had [] (0x0).

| On the otherhand linear algebra does not deal of such a notion
| either.

It can, but I would guess most texts don't bother.

| The most annoying thing is this: Matlab does not have the notion of 
orientation of vector (horizontal or vertical)
| Then why would an empty vector have such a property?

No.  What Matlab lacks is the notion of pure scalars and 1-dimensional
arrays (vectors).  Everything in Matlab has at least two dimensions,
so orientation is always explicit.

| I think it was made to ease the work of program writers by generating error 
in 
| cases where no data is get yet but the vectors are not oriented properly in 
an inner product or an outer product
| as such:
| 
| a =
| 
|    Empty matrix: 1-by-0
| 
| >> a * a
| ??? Error using ==> mtimes
| Inner matrix dimensions must agree.

Yes, that makes sense.

| I believe this can be hand but results in exceptional cases to be handled in 
most of the cases.
| Let me show another:
| 
| >> isfloat( [] )
| ans = 
|       1
| 
| why is this?

The isfloat function returns true if the argument is either single or
double (i.e., a floating point type).  By definition, the class of []
is "double".

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]