Matlab learning ------ Logical Model

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.