help-octave
[Top][All Lists]
Advanced

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

Comparison of vectors


From: John W. Eaton
Subject: Comparison of vectors
Date: Wed, 11 Nov 1998 10:45:17 -0600 (CST)

On 11-Nov-1998, Daniel Tourde <address@hidden> wrote:

| I would like to compare two vectors and to get 1 if and only if all
| their components are the same. How can I do ?

Doesn't

  all (a == b)

do what you want?

| If I use
| 
| if (A == B)
| 
| Then I obtain a vector of 0s and 1s of the length of A (resp. B) in
| function of what is matching. I just want a single answer. 1 if A is B,
| 0 otherwise.

Inside the conditional part of an if statement, all() (or all(all()),
for matrix values) is implied.

BTW, I agree that this can lead to some confusing things, like

  octave:1> a = [1,2,3,4];
  octave:2> b = [1,3,2,4];
  octave:3> if (a == b) printf ("a == b"); end
  octave:4> if (a != b) printf ("a != b"); end
  octave:5> 

(i.e., neither condition is true).  Blame this design on Matlab.
I see no way to fix it in a compatible way.

jwe



reply via email to

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