What Does the MATLAB Operator <~ Do?

  • Thread starter Thread starter Eastonc2
  • Start date Start date
  • Tags Tags
    Matlab Operator
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 2K views
Eastonc2
Messages
19
Reaction score
0

Homework Statement


I have a problem with vectors x and y, where x=[-3,0,0,2,5,8] and y=[-5,-2,0,3,4,10]
The problem asks me to determine z=y<~x
I've searched my book and cannot determine what this operator is telling me to do. Am I supposed to determine the values of y that are not less than x? I enter this exactly as stated into MATLAB and it returns a vector z=[1,1,1,0,0,0] If someone could help me out here, i'd appreciate it.

Homework Equations




The Attempt at a Solution

 
Physics news on Phys.org
Eastonc2 said:

Homework Statement


I have a problem with vectors x and y, where x=[-3,0,0,2,5,8] and y=[-5,-2,0,3,4,10]
The problem asks me to determine z=y<~x
I've searched my book and cannot determine what this operator is telling me to do. Am I supposed to determine the values of y that are not less than x? I enter this exactly as stated into MATLAB and it returns a vector z=[1,1,1,0,0,0] If someone could help me out here, i'd appreciate it.

Homework Equations




The Attempt at a Solution

~x is the complement of vector x, which evaluates to a new vector with all the signs switched.

z = y < ~ x causes each element of z to be set to 0 or 1 if an element of y is less than the corresponding element in ~x.

From you answer, I'm guessing that the problem is actually z = y <= ~x.
 
Mark44 said:
~x is the complement of vector x, which evaluates to a new vector with all the signs switched.

That's not what the ~ operator does in MATLAB. The ~ is for logical negation, which only applies to logical arrays. Any true element becomes a false element and vice versa. If x is not a logical array, I believe it is first converted into one before the negation is applied. Thus "~x" will have a 0 for every non-zero element in x, and a 1 for every element of x equal to zero.

The idea of using the < operator on a logical array seems improper to me.
 
MisterX said:
That's not what the ~ operator does in MATLAB. The ~ is for logical negation, which only applies to logical arrays. Any true element becomes a false element and vice versa. If x is not a logical array, I believe it is first converted into one before the negation is applied. Thus "~x" will have a 0 for every non-zero element in x, and a 1 for every element of x equal to zero.
Your explanation sounds reasonable to me.
MisterX said:
The idea of using the < operator on a logical array seems improper to me.
Not to me. You should be able to compare (<, <=, ==, >=, >) two logical values or two arrays of logical values.

In the OP's question, [-5, -2, 0, 3, 4, 10] is being compared to ~x = ~[-3, 0, 0, 2, 5, 8]. Each nonzero entry in ~x is replaced by 1, and each zero entry is replaced by 0, I believe. Then the two arrays are compared, element by element, with the result array having a 1 where y(i) < ~x(i), and a 0 otherwise. That's my best guess, at any rate.

I still have a concern about the 3rd element in the answer that the OP posted. I still believe that in the original problem, the comparison is <=, not <.