MATLAB Answers


"not equal to" in MATLAB

Asked by Mobile Computing on 14 Jun 2019
Latest activity Commented on by Steven Lord
on 14 Jun 2019
How do I use "not equal to" symbol in MATLAB?
The above code gives an error.


Stephen Cobeldick on 14 Jun 2019
When I searched the internet for "MATLAB not equal" this was the first link returned:
which shows all of the element-wise logical operators, with links at the bottom to the relevant pages, e.g.:
Did you try looking at the MATLAB documentation?
Steven Lord
on 14 Jun 2019
FYI for Mobile Computing, the exclamation point (bang) has a different meaning in MATLAB.

Sign in to comment.

2 Answers

Answer by Jan
on 14 Jun 2019

Several possible ways:
if 1 ~= 2
if not(1 == 2)
if ~(1==2)
if ne(1, 2)
if ~eq(1, 2)
if 1 - 2 % Implicitly evaluated: all(1 - 2)


Sign in to comment.

Answer by Manvi Goel on 14 Jun 2019

You can use the ~ instead of ! for not in MATLAB

  1 Comment

on 14 Jun 2019
"You can use..."
It's not you can. It's you have to.

Sign in to comment.