KEMBAR78
Basic operators in matlab | PPTX
Basic Operators in Matlab
Rishi PL
Department of Electronic and
Communication Engineering,
Shyamsundar PL
Department of Control System
Engineering
Operators in Matlab
● There are basic three operators in Matlab they are
● Arithmetic Operator
● Relational Operator
● Logical Operator
Arithmetic Operator
Operator Symbol
Unary Addition +
Binary Addition +
Unary Subtraction -
Binary Subtraction -
Matrix Multiplication *
Element Wise-Multiplication .*
Matrix division /
Element Wise- Division ./
Arithmetic Operator Matlab Code
4+2= +6
Matlab code: Matlab code: Matlab code:
>>4+2 >>4-2 >>4*2
>>6 >>2 >>8
Binary Operator Unary Operator
Creating the Matrix & Multiplication
In MATLAB, you create a matrix by entering elements in each row as comma or space
delimited numbers and using semicolons to mark the end of each row.
Matlab code for Matrix Creation
a = [ 1 1 1; 2 2 2;] Matlab code for multiplication
a = 1 1 1 a = [ 1 1 1; 2 2 2;] ;
2 2 2 b= [ 1 1 1; 2 2 2;] ;
c=a*b;
disp(c);
Element wise Multiplication
● For element-wise multiplication dot(.) operator is used to perform operation.
>> a=5;
>>b=6;
>>c=a.*b;
>>disp(c);
Relational Operator
Operator Symbol
Equal to ==
Not equal to ~=
Greater than >
Greater than equal >=
Less than <
Less than equal <=
Relational Operator
● Relational operator is used to perform relation of two numerical numbers that
perform some assignment operations.
Creating Unit Impulse signal using relational operator
>>t=-5:1:5;
>>impulse=t==0;
>>plot(t,impulse);
Logical Operator
Operator Symbol
AND &
OR |
NOT ~
Short circuited AND &&
Short circuited OR ||
Logical Operator
● Logical operator do operation same like AND, OR, NOT gate operations.
Short circuited AND
>>a=5;
>>b=5;
>>c=(a==5)&&(b~=5)
>>False
Short circuited OR
>>a=5;
>>b=5;
>>c=(a==5)||(b~=5)
>>True
In short circuit AND produces 0*1 = FALSE, 1*1 = TRUE (same like AND operation)
In short circuit OR produces 0+1= TRUE also 1+1 = TRUE (same like OR operation)
Basic program of multiplication of two signals
● Multiplication of decaying exponential and sine-signal using matlabclear all;
close all;
t=0:0.01:100;
a=exp(-2*t);
b=cos(2*3.14*1*t);
c=a.*b;
subplot(3,1,1)
plot(t,a);
title('decaying exponential');
xlabel('time');
ylabel('amplitude');
subplot(3,1,2)
plot(t,b);
title('sine singnal');
xlabel('time');
ylabel('amplitude');
subplot(3,1,3)
plot(t,c);
title('Multiplication of two signal');
xlabel('time');
ylabel('amplitude');
Multiplication of decaying exponential and sine-signal
THANK YOU

Basic operators in matlab

  • 1.
    Basic Operators inMatlab Rishi PL Department of Electronic and Communication Engineering, Shyamsundar PL Department of Control System Engineering
  • 2.
    Operators in Matlab ●There are basic three operators in Matlab they are ● Arithmetic Operator ● Relational Operator ● Logical Operator
  • 3.
    Arithmetic Operator Operator Symbol UnaryAddition + Binary Addition + Unary Subtraction - Binary Subtraction - Matrix Multiplication * Element Wise-Multiplication .* Matrix division / Element Wise- Division ./
  • 4.
    Arithmetic Operator MatlabCode 4+2= +6 Matlab code: Matlab code: Matlab code: >>4+2 >>4-2 >>4*2 >>6 >>2 >>8 Binary Operator Unary Operator
  • 5.
    Creating the Matrix& Multiplication In MATLAB, you create a matrix by entering elements in each row as comma or space delimited numbers and using semicolons to mark the end of each row. Matlab code for Matrix Creation a = [ 1 1 1; 2 2 2;] Matlab code for multiplication a = 1 1 1 a = [ 1 1 1; 2 2 2;] ; 2 2 2 b= [ 1 1 1; 2 2 2;] ; c=a*b; disp(c);
  • 6.
    Element wise Multiplication ●For element-wise multiplication dot(.) operator is used to perform operation. >> a=5; >>b=6; >>c=a.*b; >>disp(c);
  • 7.
    Relational Operator Operator Symbol Equalto == Not equal to ~= Greater than > Greater than equal >= Less than < Less than equal <=
  • 8.
    Relational Operator ● Relationaloperator is used to perform relation of two numerical numbers that perform some assignment operations. Creating Unit Impulse signal using relational operator >>t=-5:1:5; >>impulse=t==0; >>plot(t,impulse);
  • 9.
    Logical Operator Operator Symbol AND& OR | NOT ~ Short circuited AND && Short circuited OR ||
  • 10.
    Logical Operator ● Logicaloperator do operation same like AND, OR, NOT gate operations. Short circuited AND >>a=5; >>b=5; >>c=(a==5)&&(b~=5) >>False Short circuited OR >>a=5; >>b=5; >>c=(a==5)||(b~=5) >>True In short circuit AND produces 0*1 = FALSE, 1*1 = TRUE (same like AND operation) In short circuit OR produces 0+1= TRUE also 1+1 = TRUE (same like OR operation)
  • 11.
    Basic program ofmultiplication of two signals ● Multiplication of decaying exponential and sine-signal using matlabclear all; close all; t=0:0.01:100; a=exp(-2*t); b=cos(2*3.14*1*t); c=a.*b; subplot(3,1,1) plot(t,a); title('decaying exponential'); xlabel('time'); ylabel('amplitude'); subplot(3,1,2) plot(t,b); title('sine singnal'); xlabel('time'); ylabel('amplitude'); subplot(3,1,3) plot(t,c); title('Multiplication of two signal'); xlabel('time'); ylabel('amplitude');
  • 12.
    Multiplication of decayingexponential and sine-signal
  • 13.