6. Operators and Flow Control
Society for Industrial and Applied Mathematics eBooks · 2005
6.1. Relational and Logical Operators MATLAB has a logical data type, with the possible values 1, representing true, and 0, representing false. Logicals are produced by relational and logical operators/functions and by the functions true and false: ≫ a = true a = 1 ≫ b = false b = 0 ≫ c = 1 c = 1 ≫ whos NameSizeBytesClassa1×11logical arrayb1×11logical arrayc1×18double array Grand total is 3 elements using 10 bytes As this example shows, logicals occupy one byte, rather than the eight bytes needed by a double. MATLAB's relational operators are == equal ∼= not equal greater than = greater than or equal Note that a single = denotes assignment and never a test for equality in MATLAB. Comparisons between scalars produce logical 1 if the relation is true and logical 0 if it is false.