Confusion about logical type in MATLAB

Viewed 67

Can we compare logical to numeric type (double) in MATLAB? Why 0 <= 0.1 <= 0.2 returns 0 and 0 <= 2 <= 4 returns 1?

1 Answers

You should not read 0 <= 0.1 <= 0.2 and 0 <= 2 <= 4 in a mathematical way but in a programming way.

Considering a cast like true<-->1 and false<-->0, I mean:

  • 0<=0.1<=0.2
  • 1<=0.2 (because 0<=0.1 is true)
  • 0 (because 1<=0.2 is false)

similarly:

  • 0<=2<=4
  • 1<=4 (because 0<=2 is true)
  • 1 (because 1<=4 is true)
Related