SlideShare a Scribd company logo
1 of 14
Boolean Operators 
In Matlab
Boolean Operators 
You use logical operators in conditional 
expressions much as you use math 
operators in numeric expressions. 
SYMBOL 
in Matlab 
MEANING 
& logical AND operator 
| logical OR operator 
~ logical NOT (complement) 
xor exclusive-OR
Boolean Operators 
The & (AND) logical operator 
The & operator lets you specify multiple conditions that must be true before 
an action can be taken. 
Condition 1 Condition 2 Result of 
Condition 1 & Condition 2 
0 0 0 
0 1 0 
1 0 0 
1 1 1
Boolean Operators 
The & (AND) logical operator 
Example in Matlab: 
a = [0 0 1 1]; 
b = [0 1 0 1]; 
c = a & b 
Produces: 
c = [0 0 0 1]
Boolean Operators 
The | (OR) logical operator 
The | operator lets you create a more flexible set of conditions that must be 
met before an action can take place. 
Condition 1 Condition 2 Result of 
Condition 1 | Condition 2 
0 0 0 
0 1 1 
1 0 1 
1 1 1
Boolean Operators 
The | (OR) logical operator 
Example in Matlab: 
a = [0 0 1 1]; 
b = [0 1 0 1]; 
c = a | b 
Produces: 
c = [0 1 1 1]
Boolean Operators 
The ~ (NOT) logical operator 
The ~ operator lets you negate a condition: if a condition is false, the NOT 
operator makes the condition true; if a condition is true, NOT makes it 
false. 
Condition Result of 
~ Condition 
0 1 
1 0
Boolean Operators 
The ~ (NOT) logical operator 
Example in Matlab: 
a = [0 1]; 
b = ~a 
Produces: 
b = [1 0]
Boolean Operators 
The xor (logical exclusive-OR) 
C = xor(A, B) performs an exclusive-OR operation on the corresponding 
elements of arrays A and B. 
A B Result of 
xor(A, B) 
0 0 0 
0 1 1 
1 0 1 
1 1 0
Boolean Operators 
The xor logical operator 
Example in Matlab: 
a = [0 0 1 1]; 
b = [0 1 0 1]; 
c = xor(a, b) 
Produces: 
c = [0 1 1 0]
Relational Operators 
There are six relational operators in Matlab: 
Symbol Meaning 
< less than 
<= less than or equal 
> lreater than 
>= greater than or equal 
== equal 
~= not equal
Relational Operators 
These operations result in a vector or matrix of the same size as the 
operands, with 1 where the relation is true and 0 where it’s false. 
Example: 
If 
x = [2 5 3 9] 
y = [0 2 8 9] 
then 
If we type… We’ll get… 
a = x < y a = [0 0 1 0] 
a = x <= y a = [0 0 1 1] 
a = x > y a = [1 1 0 0] 
a = x >= y a = [1 1 0 1]
Relational and Boolean 
Operators 
Naturally, we can combine relational and boolean operators to create 
sophisticated manipulations. 
For example, if we have vector x = -5 : 10 and we want to find all the 
elements that are only within the interval -3 < x ≤ 2, we can find them like 
this: 
y = x(-3 < x & x <= 2) 
and we get: 
y = [-2 -1 0 1 2]
Boolean Operators 
For more examples and details, visit: 
matrixlab-examples.com/boolean-operator.html

More Related Content

Viewers also liked

Towers Hanoi Algorithm
Towers Hanoi AlgorithmTowers Hanoi Algorithm
Towers Hanoi AlgorithmJorge Jasso
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLABAshish Meshram
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introductionideas2ignite
 
Search Engine Powerpoint
Search Engine PowerpointSearch Engine Powerpoint
Search Engine Powerpoint201014161
 
3 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 20173 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 2017Drift
 

Viewers also liked (7)

Towers Hanoi Algorithm
Towers Hanoi AlgorithmTowers Hanoi Algorithm
Towers Hanoi Algorithm
 
Xcos scilab
Xcos scilabXcos scilab
Xcos scilab
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
 
Search Engine Powerpoint
Search Engine PowerpointSearch Engine Powerpoint
Search Engine Powerpoint
 
3 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 20173 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 2017
 

Recently uploaded

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 

Recently uploaded (20)

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 

Boolean and relational operators in Matlab

  • 2. Boolean Operators You use logical operators in conditional expressions much as you use math operators in numeric expressions. SYMBOL in Matlab MEANING & logical AND operator | logical OR operator ~ logical NOT (complement) xor exclusive-OR
  • 3. Boolean Operators The & (AND) logical operator The & operator lets you specify multiple conditions that must be true before an action can be taken. Condition 1 Condition 2 Result of Condition 1 & Condition 2 0 0 0 0 1 0 1 0 0 1 1 1
  • 4. Boolean Operators The & (AND) logical operator Example in Matlab: a = [0 0 1 1]; b = [0 1 0 1]; c = a & b Produces: c = [0 0 0 1]
  • 5. Boolean Operators The | (OR) logical operator The | operator lets you create a more flexible set of conditions that must be met before an action can take place. Condition 1 Condition 2 Result of Condition 1 | Condition 2 0 0 0 0 1 1 1 0 1 1 1 1
  • 6. Boolean Operators The | (OR) logical operator Example in Matlab: a = [0 0 1 1]; b = [0 1 0 1]; c = a | b Produces: c = [0 1 1 1]
  • 7. Boolean Operators The ~ (NOT) logical operator The ~ operator lets you negate a condition: if a condition is false, the NOT operator makes the condition true; if a condition is true, NOT makes it false. Condition Result of ~ Condition 0 1 1 0
  • 8. Boolean Operators The ~ (NOT) logical operator Example in Matlab: a = [0 1]; b = ~a Produces: b = [1 0]
  • 9. Boolean Operators The xor (logical exclusive-OR) C = xor(A, B) performs an exclusive-OR operation on the corresponding elements of arrays A and B. A B Result of xor(A, B) 0 0 0 0 1 1 1 0 1 1 1 0
  • 10. Boolean Operators The xor logical operator Example in Matlab: a = [0 0 1 1]; b = [0 1 0 1]; c = xor(a, b) Produces: c = [0 1 1 0]
  • 11. Relational Operators There are six relational operators in Matlab: Symbol Meaning < less than <= less than or equal > lreater than >= greater than or equal == equal ~= not equal
  • 12. Relational Operators These operations result in a vector or matrix of the same size as the operands, with 1 where the relation is true and 0 where it’s false. Example: If x = [2 5 3 9] y = [0 2 8 9] then If we type… We’ll get… a = x < y a = [0 0 1 0] a = x <= y a = [0 0 1 1] a = x > y a = [1 1 0 0] a = x >= y a = [1 1 0 1]
  • 13. Relational and Boolean Operators Naturally, we can combine relational and boolean operators to create sophisticated manipulations. For example, if we have vector x = -5 : 10 and we want to find all the elements that are only within the interval -3 < x ≤ 2, we can find them like this: y = x(-3 < x & x <= 2) and we get: y = [-2 -1 0 1 2]
  • 14. Boolean Operators For more examples and details, visit: matrixlab-examples.com/boolean-operator.html