"not equal to" in MATLAB
3,026 次查看(过去 30 天)
显示 更早的评论
How do I use "not equal to" symbol in MATLAB?
The above code gives an error.
回答(5 个)
Jan
2019-6-14
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)
0 个评论
Richard Payne
2021-2-20
Is there hack to accept != ?
1 个评论
Steven Lord
2021-2-21
No. The ! operator means whatever follows will be passed to the operating system (assuming it is the first part of the command, otherwise it is an error.) You cannot change that definition. The ~ operator means logical negation, and the ~= operator means not equals.
a = ~true
b = 1 ~= 2
!date
Prannoy
2023-6-4
In MATLAB, the ! operator has a separate meaning. '~' is used instead as a logical NOT operator. This means that "not equal to" will be represented by "~=" in MATLAB. I hope that clears your doubt.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!