Logical Data is either true (1) or false (0) for logical operations or relational operations.
Function (Instance) that returns the logical result ):
> M = [, 3;, 0] m = 0 4 3 0 12 0> logical (m) % converts any type of data to logical data, non-0 is logical truth, 0 is logical false ans = 0 1 1 0 1 0> true (3) % create a 3*3 logical 1 matrix ans = 1 1 1 1 1 1 1 1 1 1> true (3, 4) % create a 3*4 logical 1 matrix ans = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1> false (3,4) % create a 3*4 logical 0 matrix ans = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
MATLAB logical operators
& (Between expressions) | or (between expressions)
& And (elements one by one between two logical arrays) | or (elements one by one between two logical arrays)
~ Logical non-XOR (x, y) exclusive or (two logical arrays element by element)
Any (z) filtering (if it is a vector, if any element is not 0, 1 is returned. If it is an array, 1 is returned. If it is not 0, 1 is returned, and return 0, 1 to the new array)
All (z) detection (if it is a vector, if any element is not 0, 1 is returned; if it is an array, column-by-Column Filtering is returned; if it is not 0, 1 is returned, and return 0, 1 to the new array)
Instance:
> M = [0 4 2; 2 5 0] m = 0 4 2 5 0> N = [0, 5, 0; 0, 0, 8] n = 0 5 0 0 8> ~ M % non ans = 1 0 0 0 1> XOR (m, n) % exclusive or ans = 0 0 1 1 1> All (m) % check ans = 0 1 0> Any (m) % filter ans = 1 1 1>
Operator priority:
Priority from low to high: 1. or (|); 2. and (&); 3. logic or (|); 4. logic and (&); 5. equals to class (<,<=, >,>=, == ,~ =); 6. colon (:); 7. plus or minus (+,-); 8. multiplication and division class (DOT multiplication. *, matrix multiplication *, Division of left and right elements. \,/., matrix left and right division \,/); 9. plus or minus sign (+,-); 10. transpose class (matrix transpose. ', bounded transpose', power ^, matrix power ^)
Matlab learning ------ Logical Model