help-octave
[Top][All Lists]
Advanced

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

Re: Empty matrix question


From: John W. Eaton
Subject: Re: Empty matrix question
Date: Tue, 10 Feb 1998 16:20:17 -0600

On 10-Feb-1998, Wonkoo Kim <address@hidden> wrote:

| I don't see a statement in a octave's doc, but I would recommend you
| to allocate memory (i.e. assign) without indexing.  So the above can 
| be done as
| 
| octave:1>numfix = 5
| numfix = 5
| octave:2>vector = zeros (numfix, 1)
| vector =
| 
|   0
|   0
|   0
|   0
|   0

I'd guess that this particular case was just a simplified example.
The general problem is that you have a vector, and you want to replace
part of it with some other vector which may be empty depending on the
dimensions of your problem but you don't want to have to write special
code for the empty vector case.

I can't think of any reason right now why Octave should reject

  A(any_empty) = any_empty

in which any_empty is an empty matrix of any dimension.  However, for
actually deleting elements from a vector, I would prefer to restrict
the RHS to be [](0x0).

| > I realize that I could fix this code using something like
| >
| >   octave:56> vector(1:numfix)=zeros(numfix, (numfix>=1) );
| 
| This does not solve.

I think it does.  The expression numfix >= 1 is either 1 or 0, making
zeros(numfix, (numfix>=1)) a matrix of zeros with dimensions numfix by
1 or 0 by 0, so the dimension of the RHS always matches the dimensions
of the index range and the assignment should succeed.

In any case, here is a patch to try.

Thanks,

jwe


Tue Feb 10 16:14:36 1998  John W. Eaton  <address@hidden>

        * Array-idx.h (assign): Allow A([]) = X to succeed if X is an
        empty matrix of any dimension.


*** liboctave/Array-idx.h~      Mon May 19 16:13:51 1997
--- liboctave/Array-idx.h       Tue Feb 10 16:11:05 1998
***************
*** 244,253 ****
      }
    else
      {
!       (*current_liboctave_error_handler)
!       ("A([]) = X: X must also be an empty matrix");
  
!       retval = 0;
      }
  
    lhs.clear_index ();
--- 244,256 ----
      }
    else
      {
!       if (rhs_len != 0)
!       {
!         (*current_liboctave_error_handler)
!           ("A([]) = X: X must also be an empty matrix");
  
!         retval = 0;
!       }
      }
  
    lhs.clear_index ();



reply via email to

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