user30290
user30290

Reputation: 31

Confusion about logical type in MATLAB

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

Upvotes: 2

Views: 78

Answers (1)

Giacomo Pirinoli
Giacomo Pirinoli

Reputation: 568

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)

Upvotes: 4

Related Questions