# Matlab operator question

#### Eastonc2

1. The problem statement, all variables and given/known data
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 exaclty 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.

2. Relevant equations

3. The attempt at a solution

Related Engineering and Comp. Sci. Homework News on Phys.org

#### Mark44

Mentor
1. The problem statement, all variables and given/known data
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 exaclty 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.

2. Relevant equations

3. 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.

#### MisterX

~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.

#### Mark44

Mentor
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.
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 <.

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving