leftimage for poohprod.ru

Boolean Operator

1.- Boolean operations in Matlab

2.- Video

3.- Relational operations

1.- Introduction to Boolean operations

In Matlab, there are four logical or boolean operators:

Boolean operator: Meaning:
& logical AND
| logical OR
~ logical NOT (complement)
xor exclusive OR

These operators produce vectors or matrices of the same size as the operands, with 1 when the condition is true, and 0 when the condition is false.

2.- Video

This video gives you an overview of the operations that can be accomplished with the software, and after that, I'll show more details and exact code...

Now, let's see more details and specific examples.

Given array x = [0 7 3 5] and array y = [2 8 7 0], these are some possible operations:

Operation: Result:
n = x & y n = [0 1 1 0]
m = ~(y | x) m = [0 0 0 0]
p = xor(x, y) p = [1 0 0 1]

Since the output of the logical or boolean operations is a vector or matrix with only 0 or 1 values, the output can be used as the index of a matrix to extract appropriate elements. For example, to see the elements of x that satisfy both the conditions (x<y) and (x<4), you can type x((x<y) & (x<4)).

Operation: Result:
ans = [1 1 1 0]
x<4 ans = [1 0 0 0]
q = x((x<y) & (x<4)) q = [0 3]

Additionally to these boolean operators, there are several useful built-in logical functions, such as:

any true if any element of a vector is true
all true if all elements of a vector are true
exist true if the argument exists
isempty true for an empty matrix
isinf true for all infinite elements of a matrix
isnan true for all elements of a matrix that ara not-a-number
find finds indices of non-zero elements of a matrix

3.- Relational Operators

There are six relational operators in Matlab:

Relational operator: Meaning:
< less than
<= less than or equal
> greater than
>= greater than or equal
== equal (possibility, not assignation)
~= not equal

These operations result in a vector of matrix of the same size as the operands, with 1 when the relation is true, and 0 when it’s false.

Given arrays x = [0 7 3 5] and y = [2 8 7 0], these are some possible relational operations:

Operation: Result:
k = x<y
k = [1 1 1 0]
k = x <= y k = [1 1 1 0]
k = x == y k = [0 0 0 0]

Although these operations are usually used in conditional statements such as if-else to branch out to different cases, they can be used to do very complex matrix manipulation. For example x = y(y > 0.45) finds all the elements of vector y such that yi > 0.45 and stores them in vector x. These operations can be combined with boolean operators, too.

From 'Boolean Operator' to home

From 'Boolean Operator' to 'Boolean Algebra Menu'


Boolean Algebra Laws

Logical AND

Logical gate OR

Logical XOR

Boolean NOT

footer for boolean operator page

Related pages

binomial distribution probability calculatorhow to calculate depreciation rate formulaerrordlg matlabcount your bmitau capacitormatlab fit sine wavegraphing piecewise functions calculatorcalculate pythagorasbinary to decimal conversion methodsolve nonlinear equations matlabquadratic roots calculatorfinding piecewise functionsbinary letter chartexample of palindrome stringdepreciation value of cars calculatorbinary to ascii matlabzy smith chart colorhow to convert binary to hexadecimalbuilt in functions matlabascii value of azmatlab 3d surface plotquadratic equation c programming codematlab roots functionmatlab matrix solveplotting curves in matlabrate of depreciation calculatordefinite integrals calculatorrevolution of solidsthe unit impulse functionelectricity consumption calculatormatlab plot 3d surfacematlab summation functionfactorial with recursionhow to calculate depreciation with residual valueharmonic seriesmatlab gui textboxmatlab 3d surface plot exampleascii code for alphabets and numberssolved examples of nodal analysisthe heaviside functionsawtooth wavecompound interest spreadsheetlinear system solver matlabbinary code converter to numbershow to convert octal to binarybisection method matlab code examplesawtooth fourier transformmatlab sine wavematlab hobjectascii code lettersbinary to decimal conversion examplesconvert polar coordinates to cartesian coordinateswrite xls matlabwhile loop example matlabpie chart matlabconvert ascii code to charactergray code to binary code converterdefining function in matlabthe unit impulse functionbell shaped curve formulawriting matrices in matlabmod function in matlabmatlab 3d matrixmatlab switch statementsimple interest to compound interest converterslope and point calculatorsimpson rule calculatormatlab solving systems of equationsperiodic function definitioncramers methodpiecewise function calculator onlinehow to convert decimal to octaldepreciation formula for carsmotorcycle depreciation rate