tags:

views:

155

answers:

5

This one of the things that has always bothered me about Matlab. I understand why arrays start at 1 and not at 0 like in any other programming language, but why is != ~= in Matlab?

+6  A: 

The tilde character (~) is generally used as the bitwise NOT operator.
As the ! character is reserved for an other usage (OS command), I guess it's not a bad choice.

Macmade
+4  A: 

In mathematical logic ~ is an old-fashioned way to write ¬

Jon Hanna
A: 

In logic tilde can mean "not", which may be confusing as in math tilde can be "equivalence" or "approx". However, it is found on more keyboards than the less ambiguous ¬. Watch out, as tilde can also mean bitwise not :)

Marc Gravell
Thanks a lot everybody for your answers. They all answer my question for some part, so what should I do? Can I mark all answers as "answered"?
Ingo
@Ingo. Pick whichever seems the most complete. In a tie, pick whichever of the tied answers was earliest. If still stuck, just go for whoever you think has the best photo (this is how many vote in elections). If still stuck; write a pseudo random number generator, test its quality against NIST security tests, improve it until it passes, write a paper on a mathematical discovery you made it the course of doing so, receive a small but prestigious prize for your contribution to the state of the art, and then use the PRNG to pick an answer to select. Well, that or just picking one arbitrarily.
Jon Hanna
in a tie breaker, go for the person with the lowest rep!
Sanjay Manohar
A: 

Why is .not..eq. represented by ~= ? For the same reason that it is not represented as =!= or /= or any of the hundred and one other conventions used in programming languages.

And the twiddle, or ~, is widely used in logic texts to mean NOT.

High Performance Mark
A: 

IMO, the only answer to this question is that Cleve Moler and friends thought it better represented NOT than !=. Were they correct or not is up to individual opinion. MATLAB has a lot of other quirks that bother me a lot more than ~=, like not allowing fall through in switch-case statements and the default case being named otherwise.

Praetorian

related questions