"not equal to" in MATLAB
2 193 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
How do I use "not equal to" symbol in MATLAB?
![not_equal.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/224508/not_equal.png)
The above code gives an error.
2 commentaires
Stephen23
le 14 Juin 2019
Modifié(e) : Stephen23
le 14 Juin 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
le 14 Juin 2019
Réponses (5)
Jan
le 14 Juin 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)
0 commentaires
Richard Payne
le 20 Fév 2021
Is there hack to accept != ?
1 commentaire
Steven Lord
le 21 Fév 2021
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
le 4 Juin 2023
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 commentaires
Voir également
Catégories
En savoir plus sur Operators and Elementary Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!