octave-maintainers
[Top][All Lists]
Advanced

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

Re: Empty matrices don't have trailing ones?


From: Ben Abbott
Subject: Re: Empty matrices don't have trailing ones?
Date: Thu, 10 May 2012 07:43:23 -0400

On May 10, 2012, at 12:46 AM, Jordi Gutiérrez Hermoso wrote:

> I'm trying to figure out the rationale for having dim_vector::redim
> padding all-zero dim_vectors with zeros instead of ones. This results
> in surprising behaviour like some empty matrices getting their
> trailing dimensions being zero instead of one, so this errors out:
> 
>    x = zeros (0, 0);
>    x(:,:,1)
> 
> I don't think it should (and neither does Matlab, I'm told).

Not sure if you had any doubts about Matlab ... 

x = zeros(0,0);
x(:,:,1)

ans =

     []

> Note that
> this is a peculiarity of trailing dimensions being zero instead of the
> usual singletons.These two are fine, because dim_vector::redim doesn't
> pad them with zeros:
> 
>    x = zeros (1, 0, 0);
>    x(1,:,:)
>    x(1,:,:,1)

x = zeros(1,0,0);
x(:,:,1)
Index exceeds matrix dimensions.

x(1,:,:)

ans =

   Empty array: 1-by-0-by-0

x(1,:,:,1)

ans =

   Empty array: 1-by-0-by-0

Ben

reply via email to

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