SlideShare a Scribd company logo
http://www.tutorialspoint.com/matlab/matlab_operators.htm Copyright © tutorialspoint.com
MATLAB - OPERATORS
Anoperator is a symbolthat tells the compiler to performspecific mathematicalor logicalmanipulations.
MATLAB is designed to operate primarily onwhole matrices and arrays. Therefore, operators inMATLAB
work bothonscalar and non-scalar data. MATLAB allows the following types of elementary operations:
Arithmetic Operators
RelationalOperators
LogicalOperators
Bitwise Operations
Set Operations
Arithmetic Operators
MATLAB allows two different types of arithmetic operations:
Matrix arithmetic operations
Array arithmetic operations
Matrix arithmetic operations are same as defined inlinear algebra. Array operations are executed
element by element, bothonone-dimensionaland multidimensionalarray.
The matrix operators and array operators are differentiated by the period (.) symbol. However, as the addition
and subtractionoperationis same for matrices and arrays, the operator is same for bothcases. The following
table gives brief descriptionof the operators:
Show Examples
Operator Description
+ Additionor unary plus. A+B adds A and B. A and B must have the same size, unless one is a
scalar. A scalar canbe added to a matrix of any size.
- Subtractionor unary minus. A-B subtracts B fromA. A and B must have the same size, unless
one is a scalar. A scalar canbe subtracted froma matrix of any size.
* Matrix multiplication. C = A*B is the linear algebraic product of the matrices A and B. More
precisely,
For nonscalar A and B, the number of columns of A must equalthe number of rows of B. A
scalar canmultiply a matrix of any size.
.* Array multiplication. A.*B is the element-by-element product of the arrays A and B. A and B
must have the same size, unless one of themis a scalar.
/ Slashor matrix right division. B/A is roughly the same as B*inv(A). More precisely, B/A =
(A'B')'.
./ Array right division. A./B is the matrix withelements A(i,j)/B(i,j). A and B must have the same
size, unless one of themis a scalar.
Backslashor matrix left division. If A is a square matrix, AB is roughly the same as inv(A)*B,
except it is computed ina different way. If A is ann-by-nmatrix and B is a columnvector withn
components, or a matrix withseveralsuchcolumns, thenX = AB is the solutionto the
equationAX = B. A warning message is displayed if A is badly scaled or nearly singular.
. Array left division. A.B is the matrix withelements B(i,j)/A(i,j). A and B must have the same
size, unless one of themis a scalar.
^ Matrix power. X^p is X to the power p, if p is a scalar. If p is aninteger, the power is
computed by repeated squaring. If the integer is negative, X is inverted first. For other
values of p, the calculationinvolves eigenvalues and eigenvectors, suchthat if [V,D] = eig(X),
thenX^p = V*D.^p/V.
.^ Array power. A.^B is the matrix withelements A(i,j) to the B(i,j) power. A and B must have
the same size, unless one of themis a scalar.
' Matrix transpose. A' is the linear algebraic transpose of A. For complex matrices, this is the
complex conjugate transpose.
.' Array transpose. A.' is the array transpose of A. For complex matrices, this does not involve
conjugation.
Relational Operators
Relationaloperators canalso work onbothscalar and non-scalar data. Relationaloperators for arrays perform
element-by-element comparisons betweentwo arrays and returna logicalarray of the same size, withelements
set to logical1 (true) where the relationis true and elements set to logical0 (false) where it is not.
The following table shows the relationaloperators available inMATLAB:
Show Examples
Operator Description
< Less than
<= Less thanor equalto
> Greater than
>= Greater thanor equalto
== Equalto
~= Not equalto
Logical Operators
MATLAB offers two types of logicaloperators and functions:
Element-wise - these operators operate oncorresponding elements of logicalarrays.
Short-circuit - these operators operate onscalar, logicalexpressions.
Element-wise logicaloperators operate element-by-element onlogicalarrays. The symbols &, |, and ~ are the
logicalarray operators AND, OR, and NOT.
Short-circuit logicaloperators allow short-circuiting onlogicaloperations. The symbols && and || are the logical
short-circuit operators AND and OR.
Show Examples
Bitwise Operations
Bitwise operator works onbits and performs bit-by-bit operation. The truthtables for &, |, and ^ are as follows:
p q p & q p | q p ^ q
0 0 0 0 0
0 1 0 1 1
1 1 1 1 0
1 0 0 1 1
Assume if A = 60; and B = 13; Now inbinary format they willbe as follows:
A = 0011 1100
B = 0000 1101
-----------------
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
MATLAB provides various functions for bit-wise operations like 'bitwise and', 'bitwise or' and 'bitwise not'
operations, shift operation, etc.
The following table shows the commonly used bitwise operations:
Show Examples
Function Purpose
bitand(a, b) Bit-wise AND of integers a and b
bitcmp(a) Bit-wise complement of a
bitget(a,pos) Get bit at specified positionpos, inthe integer array a
bitor(a, b) Bit-wise OR of integers a and b
bitset(a, pos) Set bit at specific locationpos of a
bitshift(a, k) Returns a shifted to the left by k bits, equivalent to multiplying by 2k. Negative
values of k correspond to shifting bits right or dividing by 2|k| and rounding to the
nearest integer towards negative infinite. Any overflow bits are truncated.
bitxor(a, b) Bit-wise XOR of integers a and b
swapbytes Swap byte ordering
Set Operations
MATLAB provides various functions for set operations, like union, intersectionand testing for set membership,
etc.
The following table shows some commonly used set operations:
Show Examples
Function Description
intersect(A,B) Set intersectionof two arrays; returns the values commonto bothA and B. The
values returned are insorted order.
intersect(A,B,'rows') Treats eachrow of A and eachrow of B as single entities and returns the rows
commonto bothA and B. The rows of the returned matrix are insorted order.
ismember(A,B) Returns anarray the same size as A, containing 1 (true) where the elements of A
are found inB. Elsewhere, it returns 0 (false).
ismember(A,B,'rows') Treats eachrow of A and eachrow of B as single entities and returns a vector
containing 1 (true) where the rows of matrix A are also rows of B. Elsewhere, it
returns 0 (false).
issorted(A) Returns logical1 (true) if the elements of A are insorted order and logical0
(false) otherwise. Input A canbe a vector or anN-by-1 or 1-by-N cellarray of
strings. A is considered to be sorted if A and the output of sort(A) are equal.
issorted(A, 'rows') Returns logical1 (true) if the rows of two-dimensionalmatrix A are insorted
order, and logical0 (false) otherwise. Matrix A is considered to be sorted if A
and the output of sortrows(A) are equal.
setdiff(A,B) Set difference of two arrays; returns the values inA that are not inB. The values in
the returned array are insorted order.
setdiff(A,B,'rows') Treats eachrow of A and eachrow of B as single entities and returns the rows
fromA that are not inB. The rows of the returned matrix are insorted order.
The 'rows' optiondoes not support cellarrays.
setxor Set exclusive OR of two arrays
union Set unionof two arrays
unique Unique values inarray

More Related Content

What's hot

Matrixprop
MatrixpropMatrixprop
Matrixprop
Frank Lucas
 
Numerical analysis using Scilab: Numerical stability and conditioning
Numerical analysis using Scilab: Numerical stability and conditioningNumerical analysis using Scilab: Numerical stability and conditioning
Numerical analysis using Scilab: Numerical stability and conditioning
Scilab
 
Ch2
Ch2Ch2
Algebra lineal
Algebra linealAlgebra lineal
Algebra lineal
Martin Flores
 
Map algebra
Map algebraMap algebra
Map algebra
Ehsan Hamzei
 
Excel Functions
Excel Functions Excel Functions
Excel Functions
BHARAT JHA
 
Singular Value Decompostion (SVD)
Singular Value Decompostion (SVD)Singular Value Decompostion (SVD)
Singular Value Decompostion (SVD)
Isaac Yowetu
 
Operators
OperatorsOperators
Operators
jayesh30sikchi
 
Lecture 4 chapter 1 review section 2-1
Lecture 4   chapter 1 review section 2-1Lecture 4   chapter 1 review section 2-1
Lecture 4 chapter 1 review section 2-1
njit-ronbrown
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions Notes
Prof Ansari
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
Emmanuel Alimpolos
 
MS Excel: The Four Types of Operator
MS Excel: The Four Types of OperatorMS Excel: The Four Types of Operator
MS Excel: The Four Types of Operator
Jesus Obenita Jr.
 
Relational Algebra
Relational AlgebraRelational Algebra
Relational Algebra
SahilKaushik27
 
Matlab ch1 (4)
Matlab ch1 (4)Matlab ch1 (4)
Matlab ch1 (4)
mohsinggg
 
Ms excel formula
Ms excel formulaMs excel formula
Ms excel formula
Jesus Obenita Jr.
 
Flow of control
Flow of controlFlow of control
Flow of control
Saloni Singhal
 
Relational algebra calculus
Relational algebra  calculusRelational algebra  calculus
Relational algebra calculus
Vaibhav Kathuria
 
Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & Calculus
Abdullah Khosa
 

What's hot (18)

Matrixprop
MatrixpropMatrixprop
Matrixprop
 
Numerical analysis using Scilab: Numerical stability and conditioning
Numerical analysis using Scilab: Numerical stability and conditioningNumerical analysis using Scilab: Numerical stability and conditioning
Numerical analysis using Scilab: Numerical stability and conditioning
 
Ch2
Ch2Ch2
Ch2
 
Algebra lineal
Algebra linealAlgebra lineal
Algebra lineal
 
Map algebra
Map algebraMap algebra
Map algebra
 
Excel Functions
Excel Functions Excel Functions
Excel Functions
 
Singular Value Decompostion (SVD)
Singular Value Decompostion (SVD)Singular Value Decompostion (SVD)
Singular Value Decompostion (SVD)
 
Operators
OperatorsOperators
Operators
 
Lecture 4 chapter 1 review section 2-1
Lecture 4   chapter 1 review section 2-1Lecture 4   chapter 1 review section 2-1
Lecture 4 chapter 1 review section 2-1
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions Notes
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
 
MS Excel: The Four Types of Operator
MS Excel: The Four Types of OperatorMS Excel: The Four Types of Operator
MS Excel: The Four Types of Operator
 
Relational Algebra
Relational AlgebraRelational Algebra
Relational Algebra
 
Matlab ch1 (4)
Matlab ch1 (4)Matlab ch1 (4)
Matlab ch1 (4)
 
Ms excel formula
Ms excel formulaMs excel formula
Ms excel formula
 
Flow of control
Flow of controlFlow of control
Flow of control
 
Relational algebra calculus
Relational algebra  calculusRelational algebra  calculus
Relational algebra calculus
 
Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & Calculus
 

Viewers also liked

C24 company overview brochure lowres
C24 company overview brochure lowresC24 company overview brochure lowres
C24 company overview brochure lowres
David Ricketts
 
Matlab differential
Matlab differentialMatlab differential
Matlab differential
pramodkumar1804
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
pramodkumar1804
 
Matlab operators
Matlab operatorsMatlab operators
Matlab operators
pramodkumar1804
 
Matlab syntax
Matlab syntaxMatlab syntax
Matlab syntax
pramodkumar1804
 
C24 wright hassall casestudy a4 3pp
C24 wright hassall casestudy a4 3ppC24 wright hassall casestudy a4 3pp
C24 wright hassall casestudy a4 3pp
David Ricketts
 
C24 bi datasheet leading in the legal sector with big data
C24 bi datasheet leading in the legal sector with big dataC24 bi datasheet leading in the legal sector with big data
C24 bi datasheet leading in the legal sector with big data
David Ricketts
 
Matlab gnu octave
Matlab gnu octaveMatlab gnu octave
Matlab gnu octave
pramodkumar1804
 
Matlab algebra
Matlab algebraMatlab algebra
Matlab algebra
pramodkumar1804
 
Matlab numbers
Matlab numbersMatlab numbers
Matlab numbers
pramodkumar1804
 
Effective resume writing
Effective resume writingEffective resume writing
Effective resume writing
pramodkumar1804
 
Matlab calculus
Matlab calculusMatlab calculus
Matlab calculus
pramodkumar1804
 
Matlab simulink
Matlab simulinkMatlab simulink
Matlab simulink
pramodkumar1804
 
Matlab data import
Matlab data importMatlab data import
Matlab data import
pramodkumar1804
 
Matlab integration
Matlab integrationMatlab integration
Matlab integration
pramodkumar1804
 
Matlab functions
Matlab functionsMatlab functions
Matlab functions
pramodkumar1804
 
Matlab strings
Matlab stringsMatlab strings
Matlab strings
pramodkumar1804
 
C24 Arthur Terry Case Study 365
C24 Arthur Terry Case Study 365C24 Arthur Terry Case Study 365
C24 Arthur Terry Case Study 365
David Ricketts
 

Viewers also liked (18)

C24 company overview brochure lowres
C24 company overview brochure lowresC24 company overview brochure lowres
C24 company overview brochure lowres
 
Matlab differential
Matlab differentialMatlab differential
Matlab differential
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
Matlab operators
Matlab operatorsMatlab operators
Matlab operators
 
Matlab syntax
Matlab syntaxMatlab syntax
Matlab syntax
 
C24 wright hassall casestudy a4 3pp
C24 wright hassall casestudy a4 3ppC24 wright hassall casestudy a4 3pp
C24 wright hassall casestudy a4 3pp
 
C24 bi datasheet leading in the legal sector with big data
C24 bi datasheet leading in the legal sector with big dataC24 bi datasheet leading in the legal sector with big data
C24 bi datasheet leading in the legal sector with big data
 
Matlab gnu octave
Matlab gnu octaveMatlab gnu octave
Matlab gnu octave
 
Matlab algebra
Matlab algebraMatlab algebra
Matlab algebra
 
Matlab numbers
Matlab numbersMatlab numbers
Matlab numbers
 
Effective resume writing
Effective resume writingEffective resume writing
Effective resume writing
 
Matlab calculus
Matlab calculusMatlab calculus
Matlab calculus
 
Matlab simulink
Matlab simulinkMatlab simulink
Matlab simulink
 
Matlab data import
Matlab data importMatlab data import
Matlab data import
 
Matlab integration
Matlab integrationMatlab integration
Matlab integration
 
Matlab functions
Matlab functionsMatlab functions
Matlab functions
 
Matlab strings
Matlab stringsMatlab strings
Matlab strings
 
C24 Arthur Terry Case Study 365
C24 Arthur Terry Case Study 365C24 Arthur Terry Case Study 365
C24 Arthur Terry Case Study 365
 

Similar to Matlab operators

Matlab practical ---4.pdf
Matlab practical ---4.pdfMatlab practical ---4.pdf
Matlab practical ---4.pdf
Central university of Haryana
 
matlab functions
 matlab functions  matlab functions
matlab functions
DINESH DEVIREDDY
 
Lesson 6
Lesson 6Lesson 6
Lesson 6
Vinnu Vinay
 
Commands list
Commands listCommands list
Commands list
PRAVEENKUMAR CHIKOTI
 
matrix algebra
matrix algebramatrix algebra
matrix algebra
kganu
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
AMANPATHAK87
 
Matlab tut3
Matlab tut3Matlab tut3
Matlab tut3
Vinnu Vinay
 
Matrices And Determinants
Matrices And DeterminantsMatrices And Determinants
Matrices And Determinants
DEVIKA S INDU
 
1. Introduction.pptx
1. Introduction.pptx1. Introduction.pptx
1. Introduction.pptx
SungaleliYuen
 
02 linear algebra
02 linear algebra02 linear algebra
02 linear algebra
HusseinZein5
 
02 linear algebra
02 linear algebra02 linear algebra
02 linear algebra
Ronald Teo
 
Mat lab.pptx
Mat lab.pptxMat lab.pptx
Mat lab.pptx
MeshackDuru
 
Linear_Algebra_final.pdf
Linear_Algebra_final.pdfLinear_Algebra_final.pdf
Linear_Algebra_final.pdf
RohitAnand125
 
Additional Relational Algebra Operations
Additional Relational Algebra OperationsAdditional Relational Algebra Operations
Additional Relational Algebra Operations
A. S. M. Shafi
 
Matrices y determinants
Matrices y determinantsMatrices y determinants
Matrices y determinants
Jeannie
 
Engg maths k notes(4)
Engg maths k notes(4)Engg maths k notes(4)
Engg maths k notes(4)
Ranjay Kumar
 
Matrix
MatrixMatrix
Matrix
Umar Farooq
 
1
11
Operator 04 (js)
Operator 04 (js)Operator 04 (js)
Operator 04 (js)
AbhishekMondal42
 
Matrices ,Basics, Determinant, Inverse, EigenValues, Linear Equations, RANK
Matrices ,Basics, Determinant, Inverse, EigenValues, Linear Equations, RANKMatrices ,Basics, Determinant, Inverse, EigenValues, Linear Equations, RANK
Matrices ,Basics, Determinant, Inverse, EigenValues, Linear Equations, RANK
Waqas Afzal
 

Similar to Matlab operators (20)

Matlab practical ---4.pdf
Matlab practical ---4.pdfMatlab practical ---4.pdf
Matlab practical ---4.pdf
 
matlab functions
 matlab functions  matlab functions
matlab functions
 
Lesson 6
Lesson 6Lesson 6
Lesson 6
 
Commands list
Commands listCommands list
Commands list
 
matrix algebra
matrix algebramatrix algebra
matrix algebra
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
Matlab tut3
Matlab tut3Matlab tut3
Matlab tut3
 
Matrices And Determinants
Matrices And DeterminantsMatrices And Determinants
Matrices And Determinants
 
1. Introduction.pptx
1. Introduction.pptx1. Introduction.pptx
1. Introduction.pptx
 
02 linear algebra
02 linear algebra02 linear algebra
02 linear algebra
 
02 linear algebra
02 linear algebra02 linear algebra
02 linear algebra
 
Mat lab.pptx
Mat lab.pptxMat lab.pptx
Mat lab.pptx
 
Linear_Algebra_final.pdf
Linear_Algebra_final.pdfLinear_Algebra_final.pdf
Linear_Algebra_final.pdf
 
Additional Relational Algebra Operations
Additional Relational Algebra OperationsAdditional Relational Algebra Operations
Additional Relational Algebra Operations
 
Matrices y determinants
Matrices y determinantsMatrices y determinants
Matrices y determinants
 
Engg maths k notes(4)
Engg maths k notes(4)Engg maths k notes(4)
Engg maths k notes(4)
 
Matrix
MatrixMatrix
Matrix
 
1
11
1
 
Operator 04 (js)
Operator 04 (js)Operator 04 (js)
Operator 04 (js)
 
Matrices ,Basics, Determinant, Inverse, EigenValues, Linear Equations, RANK
Matrices ,Basics, Determinant, Inverse, EigenValues, Linear Equations, RANKMatrices ,Basics, Determinant, Inverse, EigenValues, Linear Equations, RANK
Matrices ,Basics, Determinant, Inverse, EigenValues, Linear Equations, RANK
 

More from pramodkumar1804

Matlab polynomials
Matlab polynomialsMatlab polynomials
Matlab polynomials
pramodkumar1804
 
Matlab overview 3
Matlab overview 3Matlab overview 3
Matlab overview 3
pramodkumar1804
 
Matlab overview 2
Matlab overview 2Matlab overview 2
Matlab overview 2
pramodkumar1804
 
Matlab overview
Matlab overviewMatlab overview
Matlab overview
pramodkumar1804
 
Matlab variables
Matlab variablesMatlab variables
Matlab variables
pramodkumar1804
 
Matlab matrics
Matlab matricsMatlab matrics
Matlab matrics
pramodkumar1804
 
Matlab m files
Matlab m filesMatlab m files
Matlab m files
pramodkumar1804
 
Matlab loops 2
Matlab loops 2Matlab loops 2
Matlab loops 2
pramodkumar1804
 
Matlab loops
Matlab loopsMatlab loops
Matlab loops
pramodkumar1804
 
Matlab graphics
Matlab graphicsMatlab graphics
Matlab graphics
pramodkumar1804
 
Matlab decisions
Matlab decisionsMatlab decisions
Matlab decisions
pramodkumar1804
 
Matlab colon notation
Matlab colon notationMatlab colon notation
Matlab colon notation
pramodkumar1804
 
Matlab vectors
Matlab vectorsMatlab vectors
Matlab vectors
pramodkumar1804
 

More from pramodkumar1804 (13)

Matlab polynomials
Matlab polynomialsMatlab polynomials
Matlab polynomials
 
Matlab overview 3
Matlab overview 3Matlab overview 3
Matlab overview 3
 
Matlab overview 2
Matlab overview 2Matlab overview 2
Matlab overview 2
 
Matlab overview
Matlab overviewMatlab overview
Matlab overview
 
Matlab variables
Matlab variablesMatlab variables
Matlab variables
 
Matlab matrics
Matlab matricsMatlab matrics
Matlab matrics
 
Matlab m files
Matlab m filesMatlab m files
Matlab m files
 
Matlab loops 2
Matlab loops 2Matlab loops 2
Matlab loops 2
 
Matlab loops
Matlab loopsMatlab loops
Matlab loops
 
Matlab graphics
Matlab graphicsMatlab graphics
Matlab graphics
 
Matlab decisions
Matlab decisionsMatlab decisions
Matlab decisions
 
Matlab colon notation
Matlab colon notationMatlab colon notation
Matlab colon notation
 
Matlab vectors
Matlab vectorsMatlab vectors
Matlab vectors
 

Recently uploaded

বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 

Recently uploaded (20)

বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 

Matlab operators

  • 1. http://www.tutorialspoint.com/matlab/matlab_operators.htm Copyright © tutorialspoint.com MATLAB - OPERATORS Anoperator is a symbolthat tells the compiler to performspecific mathematicalor logicalmanipulations. MATLAB is designed to operate primarily onwhole matrices and arrays. Therefore, operators inMATLAB work bothonscalar and non-scalar data. MATLAB allows the following types of elementary operations: Arithmetic Operators RelationalOperators LogicalOperators Bitwise Operations Set Operations Arithmetic Operators MATLAB allows two different types of arithmetic operations: Matrix arithmetic operations Array arithmetic operations Matrix arithmetic operations are same as defined inlinear algebra. Array operations are executed element by element, bothonone-dimensionaland multidimensionalarray. The matrix operators and array operators are differentiated by the period (.) symbol. However, as the addition and subtractionoperationis same for matrices and arrays, the operator is same for bothcases. The following table gives brief descriptionof the operators: Show Examples Operator Description + Additionor unary plus. A+B adds A and B. A and B must have the same size, unless one is a scalar. A scalar canbe added to a matrix of any size. - Subtractionor unary minus. A-B subtracts B fromA. A and B must have the same size, unless one is a scalar. A scalar canbe subtracted froma matrix of any size. * Matrix multiplication. C = A*B is the linear algebraic product of the matrices A and B. More precisely, For nonscalar A and B, the number of columns of A must equalthe number of rows of B. A scalar canmultiply a matrix of any size. .* Array multiplication. A.*B is the element-by-element product of the arrays A and B. A and B must have the same size, unless one of themis a scalar. / Slashor matrix right division. B/A is roughly the same as B*inv(A). More precisely, B/A = (A'B')'. ./ Array right division. A./B is the matrix withelements A(i,j)/B(i,j). A and B must have the same size, unless one of themis a scalar.
  • 2. Backslashor matrix left division. If A is a square matrix, AB is roughly the same as inv(A)*B, except it is computed ina different way. If A is ann-by-nmatrix and B is a columnvector withn components, or a matrix withseveralsuchcolumns, thenX = AB is the solutionto the equationAX = B. A warning message is displayed if A is badly scaled or nearly singular. . Array left division. A.B is the matrix withelements B(i,j)/A(i,j). A and B must have the same size, unless one of themis a scalar. ^ Matrix power. X^p is X to the power p, if p is a scalar. If p is aninteger, the power is computed by repeated squaring. If the integer is negative, X is inverted first. For other values of p, the calculationinvolves eigenvalues and eigenvectors, suchthat if [V,D] = eig(X), thenX^p = V*D.^p/V. .^ Array power. A.^B is the matrix withelements A(i,j) to the B(i,j) power. A and B must have the same size, unless one of themis a scalar. ' Matrix transpose. A' is the linear algebraic transpose of A. For complex matrices, this is the complex conjugate transpose. .' Array transpose. A.' is the array transpose of A. For complex matrices, this does not involve conjugation. Relational Operators Relationaloperators canalso work onbothscalar and non-scalar data. Relationaloperators for arrays perform element-by-element comparisons betweentwo arrays and returna logicalarray of the same size, withelements set to logical1 (true) where the relationis true and elements set to logical0 (false) where it is not. The following table shows the relationaloperators available inMATLAB: Show Examples Operator Description < Less than <= Less thanor equalto > Greater than >= Greater thanor equalto == Equalto ~= Not equalto Logical Operators MATLAB offers two types of logicaloperators and functions: Element-wise - these operators operate oncorresponding elements of logicalarrays. Short-circuit - these operators operate onscalar, logicalexpressions. Element-wise logicaloperators operate element-by-element onlogicalarrays. The symbols &, |, and ~ are the logicalarray operators AND, OR, and NOT. Short-circuit logicaloperators allow short-circuiting onlogicaloperations. The symbols && and || are the logical short-circuit operators AND and OR.
  • 3. Show Examples Bitwise Operations Bitwise operator works onbits and performs bit-by-bit operation. The truthtables for &, |, and ^ are as follows: p q p & q p | q p ^ q 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1 Assume if A = 60; and B = 13; Now inbinary format they willbe as follows: A = 0011 1100 B = 0000 1101 ----------------- A&B = 0000 1100 A|B = 0011 1101 A^B = 0011 0001 ~A = 1100 0011 MATLAB provides various functions for bit-wise operations like 'bitwise and', 'bitwise or' and 'bitwise not' operations, shift operation, etc. The following table shows the commonly used bitwise operations: Show Examples Function Purpose bitand(a, b) Bit-wise AND of integers a and b bitcmp(a) Bit-wise complement of a bitget(a,pos) Get bit at specified positionpos, inthe integer array a bitor(a, b) Bit-wise OR of integers a and b bitset(a, pos) Set bit at specific locationpos of a bitshift(a, k) Returns a shifted to the left by k bits, equivalent to multiplying by 2k. Negative values of k correspond to shifting bits right or dividing by 2|k| and rounding to the nearest integer towards negative infinite. Any overflow bits are truncated. bitxor(a, b) Bit-wise XOR of integers a and b swapbytes Swap byte ordering Set Operations
  • 4. MATLAB provides various functions for set operations, like union, intersectionand testing for set membership, etc. The following table shows some commonly used set operations: Show Examples Function Description intersect(A,B) Set intersectionof two arrays; returns the values commonto bothA and B. The values returned are insorted order. intersect(A,B,'rows') Treats eachrow of A and eachrow of B as single entities and returns the rows commonto bothA and B. The rows of the returned matrix are insorted order. ismember(A,B) Returns anarray the same size as A, containing 1 (true) where the elements of A are found inB. Elsewhere, it returns 0 (false). ismember(A,B,'rows') Treats eachrow of A and eachrow of B as single entities and returns a vector containing 1 (true) where the rows of matrix A are also rows of B. Elsewhere, it returns 0 (false). issorted(A) Returns logical1 (true) if the elements of A are insorted order and logical0 (false) otherwise. Input A canbe a vector or anN-by-1 or 1-by-N cellarray of strings. A is considered to be sorted if A and the output of sort(A) are equal. issorted(A, 'rows') Returns logical1 (true) if the rows of two-dimensionalmatrix A are insorted order, and logical0 (false) otherwise. Matrix A is considered to be sorted if A and the output of sortrows(A) are equal. setdiff(A,B) Set difference of two arrays; returns the values inA that are not inB. The values in the returned array are insorted order. setdiff(A,B,'rows') Treats eachrow of A and eachrow of B as single entities and returns the rows fromA that are not inB. The rows of the returned matrix are insorted order. The 'rows' optiondoes not support cellarrays. setxor Set exclusive OR of two arrays union Set unionof two arrays unique Unique values inarray