octave-maintainers
[Top][All Lists]
Advanced

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

Re: fix null assignment


From: Levente Torok
Subject: Re: fix null assignment
Date: Thu, 18 Sep 2008 15:56:26 +0200
User-agent: KMail/1.9.6 (enterprise 0.20070907.709405)

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.

Or.
a' * a
ans = 
   0

a * a'
   []

I think this is very much arbitrary think.

I checked documentation of Matlab and I found no notion of empty vectors:
http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/sum.html

On the otherhand linear algebra does not deal of such a notion either.
I feel it to be a bit similar case to operating (0/0) or with inf values.

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?

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.

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?

Levente

On Thursday 18 September 2008, Jaroslav Hajek wrote:
> On Thu, Sep 18, 2008 at 2:23 PM, Levente Torok <address@hidden> wrote:
> > On Thursday 18 September 2008, Jaroslav Hajek wrote:
> >
> > Hi all,
> >
> > However, I think matlab compatibility is the top priority
> > I believe octave was much more consistent in terms of mat
> >
> >> hello,
> >>
> >> the attached patch fixes the following problems / Matlab
> >> incompatibilities with null assignment in Octave.
> >>
> >> 2. a = 1:5; a(1:5) = []
> >> --> a is 0-by-0 in Octave, 1-by-0 in Matlab
> >
> >> 3. a = 1:5; a = a'; a(1:5) = []
> >> --> a is 0-by-0 in Octave, 0-by-1 in Matlab
> >
> >
> >> 4. a = ones (3); a(:,:) = []
> >> --> a is 0-by-0 in Octave, 0-by-3 in Matlab
> >
> >> 5. a = ones (3); a(1:3,1:3) = []
> >> --> a is 0-by-0 in Octave, error in Matlab
> >
> >> 6. a = ones (3); a(1:2,1:2) = []
> >> --> a is unaffected in Octave (! BUG), error in Matlab
> >
> > I don't believe it makes much sense to follow Matlab in these aspects
> > with the exception of the bug.
> >
> > To make myself clear why I think so:
> >
> > a = 1:5; a(1:5) = []; a * a'
> > is 0 in matlab and ans = [](0x0)
> >
> > While the matlab version is handy when dealing with real data but faulty in 
> > terms of math.
> > I mean how can a scalar product equal to 0 when there are no items in the 
> > product.
> >
> 

> An empty sum is *defined* to be zero, 
> and a matrix product with the 
> *inner* dimension empty is nothing else than an empty sum.
> Therefore, this behaviour is completely OK. I'm glad that it also
> works with the patch I've posted.


> Similarly, an empty product is defined as unity.
??
I guess you meant zero instead of unity.

Lev

-- 
Blogger of http://fapuma.blogspot.com


reply via email to

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