[Top][All Lists]

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

Re: manipulation of matrix elements

From: John W. Eaton
Subject: Re: manipulation of matrix elements
Date: Thu, 16 Dec 1999 11:27:21 -0600 (CST)

On 16-Dec-1999, Michael Roth <address@hidden> wrote:

| However, I get different results, if the condition is fulfilled for an
| entire row or column.     
| For example for the matrix s=[0.3 0.3; 0.7 0.7]
| you get with  [i,j]=find(s<=0.5);s(i,j)=0.5
|      in octave          |    in matlab (Version
|                         |
|   s = 0.5000    0.5000  |    s = 0.5000    0.5000
|       0.5000    0.5000  |        0.7000    0.7000

What version of Octave?  with 2.0.14, I get:

  GNU Octave, version 2.0.14 (i686-pc-linux-gnu).
  Copyright (C) 1996, 1997, 1998, 1999 John W. Eaton.
  This is free software with ABSOLUTELY NO WARRANTY.
  For details, type `warranty'.

  octave:1> s=[0.3 0.3; 0.7 0.7]
  s =

    0.30000  0.30000
    0.70000  0.70000

  octave:2> [i,j]=find(s<=0.5);s(i,j)=0.5
  s =

    0.50000  0.50000
    0.70000  0.70000

Which is correct, but maybe not for the reason you are thinking.
I.e., it does not do the equivalent of:

  for ii = 1:2
    for jj = 1:2
      s(i(ii),j(jj)) = RHS;

Instead, it sets all the values specified by the intersection of the
rows i and columns j to the RHS value.  when the rows or columns are
all the same, it appears to be equivalent to the loop above.

Ah, I just realized that if you are going for maximum Matlab
compatibility, then you probably have prefer_zero_one_indexing set to
a non-zero value.  If so, I think that is the reason for the trouble,
and why you see the different result.  Check out the documentation for
that variable.  If you still don't see why you end up getting all the
elements set to the RHS value for the case above, post a message to
the help-octave mailing list.

FWIW, this ambiguity in the language is avoided in the development
versions of Octave by introducing a new boolean data type (like
Matlab's logical type, which was introduced in Matlab 5) and requiring
`zero-one' style indexing to be done with boolean objects instead of
just vectors of ones and zeros.


Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

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