SlideShare a Scribd company logo
1 of 17
Logical Vectors and
      Strings
• TYPE as it is in Command Line :
   r=1; Chk result
  r<=.5
   ( Result is 0)
   and then at last
   r>=.5
( Result is 1)

Now Enter the Following statement :

r = 1:5;
r<=3

U get 11100 as statement is true for first 3 elements
• Vectors are compared element by element
  and the resulting vector is called as Logical
  Vector. It is one of the most power concepts in
  MATLAB.

• For eg try this :
a=1:5;
b=[0 2 3 5 6];
a==b % no semicolon (Result is :
0 1 1 0 0)
• Applications :
Discontinuous Graphs :




Type these Statements :
x=0:pi/20:3*pi;
y=sin(x);
y=y .* (y>0);
plot(x,y)
• What was the Funda ???
y>0 returns a logical vector with ones where sin(x)
  is positive as y>0 means it is checked element
  by element if it is >0 ; and if it is not then it
  returns 0.

After this we multiply by y to get the graph
• Avoid division by 0




As one of the element of x is exact zero.
• Use Logical Vector to replace zero with eps.




What is eps?
• This MATLAB function returns the difference
  between 1.0 and the next largest number which
  can be represented in MATLAB, i.e.
  approximately 2.2e-16.
• So you type and get :
• Logical Functions :
x is a vector :
Try these statements :

x=1:5
any(x)

any(x) : returns scalar 1 in ans if any element of x
  is nonzero.
• Try for the o/p of
 x = [ 0 0]
any(x)

all(x)
Returns scalar 1 if all elements of vector x r non
   zero!
x=1:5;
all(x)
Try to get info abt all logic functions
• Strings :
• For Basic i/p o/p of string we have :

name = input( 'Enter your surname: ', 's' );

Chk the workspace

Now type

disp(name)
Logical vectors
Logical vectors
Logical vectors

More Related Content

What's hot

Divide and conquer 1
Divide and conquer 1Divide and conquer 1
Divide and conquer 1Kumar
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsHoang Nguyen
 
Counting Sort Lowerbound
Counting Sort LowerboundCounting Sort Lowerbound
Counting Sort Lowerbounddespicable me
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsDrishti Bhalla
 
Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0BG Java EE Course
 
Python decision making_loops_control statements part9
Python decision making_loops_control statements part9Python decision making_loops_control statements part9
Python decision making_loops_control statements part9Vishal Dutt
 
Matlab on basic mathematics
Matlab on basic mathematicsMatlab on basic mathematics
Matlab on basic mathematicsmonauweralam1
 
Big oh Representation Used in Time complexities
Big oh Representation Used in Time complexitiesBig oh Representation Used in Time complexities
Big oh Representation Used in Time complexitiesLAKSHMITHARUN PONNAM
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked ListsJ.T.A.JONES
 

What's hot (20)

Divide and conquer 1
Divide and conquer 1Divide and conquer 1
Divide and conquer 1
 
Best,worst,average case .17581556 045
Best,worst,average case .17581556 045Best,worst,average case .17581556 045
Best,worst,average case .17581556 045
 
Functions lect
Functions lectFunctions lect
Functions lect
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Lecture4
Lecture4Lecture4
Lecture4
 
Counting sort
Counting sortCounting sort
Counting sort
 
L10 sorting-searching
L10 sorting-searchingL10 sorting-searching
L10 sorting-searching
 
Counting Sort Lowerbound
Counting Sort LowerboundCounting Sort Lowerbound
Counting Sort Lowerbound
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 
Counting sort
Counting sortCounting sort
Counting sort
 
Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0
 
Python decision making_loops_control statements part9
Python decision making_loops_control statements part9Python decision making_loops_control statements part9
Python decision making_loops_control statements part9
 
Arrays.pptx
Arrays.pptxArrays.pptx
Arrays.pptx
 
Matlab on basic mathematics
Matlab on basic mathematicsMatlab on basic mathematics
Matlab on basic mathematics
 
MATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesMATLAB - Arrays and Matrices
MATLAB - Arrays and Matrices
 
Insertion sort algorithm power point presentation
Insertion  sort algorithm power point presentation Insertion  sort algorithm power point presentation
Insertion sort algorithm power point presentation
 
Big oh Representation Used in Time complexities
Big oh Representation Used in Time complexitiesBig oh Representation Used in Time complexities
Big oh Representation Used in Time complexities
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
 
Big o notation
Big o notationBig o notation
Big o notation
 

Viewers also liked (20)

Michaelpritchard
MichaelpritchardMichaelpritchard
Michaelpritchard
 
Matlab
MatlabMatlab
Matlab
 
Tech tut
Tech tutTech tut
Tech tut
 
VPN
VPNVPN
VPN
 
Improving your driveway, path or patio.
Improving  your driveway, path or patio.Improving  your driveway, path or patio.
Improving your driveway, path or patio.
 
Michaelpritchard
MichaelpritchardMichaelpritchard
Michaelpritchard
 
Lec2
Lec2Lec2
Lec2
 
Matlab
MatlabMatlab
Matlab
 
Lec1
Lec1Lec1
Lec1
 
Fb Nnew Pps
Fb Nnew PpsFb Nnew Pps
Fb Nnew Pps
 
Matlab graphics
Matlab graphicsMatlab graphics
Matlab graphics
 
SIB Green IT Policy
SIB Green IT PolicySIB Green IT Policy
SIB Green IT Policy
 
BarCamp in Saigon
BarCamp in SaigonBarCamp in Saigon
BarCamp in Saigon
 
Introduction into GIT
Introduction into GITIntroduction into GIT
Introduction into GIT
 
An approach to implement model classes in zend
An approach to implement model classes in zendAn approach to implement model classes in zend
An approach to implement model classes in zend
 
Los espacios en la BECREA. junta de andalucía.
Los espacios en la BECREA. junta de andalucía.Los espacios en la BECREA. junta de andalucía.
Los espacios en la BECREA. junta de andalucía.
 
Servicios tradicionales en la BECREA
Servicios tradicionales en la BECREAServicios tradicionales en la BECREA
Servicios tradicionales en la BECREA
 
How to apply Agile in Marketing
How to apply Agile in MarketingHow to apply Agile in Marketing
How to apply Agile in Marketing
 
GUÍA DE BIBLIOTECAS ESCOLARES. 6. Extensión cultural. Director: José García G...
GUÍA DE BIBLIOTECAS ESCOLARES. 6. Extensión cultural. Director: José García G...GUÍA DE BIBLIOTECAS ESCOLARES. 6. Extensión cultural. Director: José García G...
GUÍA DE BIBLIOTECAS ESCOLARES. 6. Extensión cultural. Director: José García G...
 
Client Satisfaction as engine of the continuous improvement
Client Satisfaction as engine of the continuous improvementClient Satisfaction as engine of the continuous improvement
Client Satisfaction as engine of the continuous improvement
 

Similar to Logical vectors

A MATLAB project on LCR circuits
A MATLAB project on LCR circuitsA MATLAB project on LCR circuits
A MATLAB project on LCR circuitssvrohith 9
 
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkMATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkreddyprasad reddyvari
 
Presentación grupo 551108 30
Presentación grupo 551108 30Presentación grupo 551108 30
Presentación grupo 551108 30njhernandez19
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functionsjoellivz
 
Domain and range (linear, quadratic, rational functions)
Domain and range (linear, quadratic, rational functions)Domain and range (linear, quadratic, rational functions)
Domain and range (linear, quadratic, rational functions)Rose Mary Tania Arini
 
Dsp manual completed2
Dsp manual completed2Dsp manual completed2
Dsp manual completed2bilawalali74
 
chapter1.pdf ......................................
chapter1.pdf ......................................chapter1.pdf ......................................
chapter1.pdf ......................................nourhandardeer3
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to MatlabAmr Rashed
 
MATLAB-Introd.ppt
MATLAB-Introd.pptMATLAB-Introd.ppt
MATLAB-Introd.pptkebeAman
 

Similar to Logical vectors (20)

2. Chap 1.pptx
2. Chap 1.pptx2. Chap 1.pptx
2. Chap 1.pptx
 
Matlab practical ---4.pdf
Matlab practical ---4.pdfMatlab practical ---4.pdf
Matlab practical ---4.pdf
 
Advance algebra
Advance algebraAdvance algebra
Advance algebra
 
A MATLAB project on LCR circuits
A MATLAB project on LCR circuitsA MATLAB project on LCR circuits
A MATLAB project on LCR circuits
 
bisection method
bisection methodbisection method
bisection method
 
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkMATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
 
Presentación grupo 551108 30
Presentación grupo 551108 30Presentación grupo 551108 30
Presentación grupo 551108 30
 
Exponents
ExponentsExponents
Exponents
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
 
Matlab for marketing people
Matlab for marketing peopleMatlab for marketing people
Matlab for marketing people
 
Domain and range (linear, quadratic, rational functions)
Domain and range (linear, quadratic, rational functions)Domain and range (linear, quadratic, rational functions)
Domain and range (linear, quadratic, rational functions)
 
Lec3
Lec3Lec3
Lec3
 
Dsp manual completed2
Dsp manual completed2Dsp manual completed2
Dsp manual completed2
 
Functions lesson
Functions lesson Functions lesson
Functions lesson
 
chapter1.pdf ......................................
chapter1.pdf ......................................chapter1.pdf ......................................
chapter1.pdf ......................................
 
Matlab1
Matlab1Matlab1
Matlab1
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
MATLAB-Introd.ppt
MATLAB-Introd.pptMATLAB-Introd.ppt
MATLAB-Introd.ppt
 

Recently uploaded

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
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
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 

Recently uploaded (20)

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
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
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 

Logical vectors

  • 2. • TYPE as it is in Command Line : r=1; Chk result r<=.5 ( Result is 0) and then at last r>=.5 ( Result is 1) Now Enter the Following statement : r = 1:5; r<=3 U get 11100 as statement is true for first 3 elements
  • 3. • Vectors are compared element by element and the resulting vector is called as Logical Vector. It is one of the most power concepts in MATLAB. • For eg try this : a=1:5; b=[0 2 3 5 6]; a==b % no semicolon (Result is : 0 1 1 0 0)
  • 4. • Applications : Discontinuous Graphs : Type these Statements : x=0:pi/20:3*pi; y=sin(x); y=y .* (y>0); plot(x,y)
  • 5. • What was the Funda ??? y>0 returns a logical vector with ones where sin(x) is positive as y>0 means it is checked element by element if it is >0 ; and if it is not then it returns 0. After this we multiply by y to get the graph
  • 6. • Avoid division by 0 As one of the element of x is exact zero.
  • 7. • Use Logical Vector to replace zero with eps. What is eps? • This MATLAB function returns the difference between 1.0 and the next largest number which can be represented in MATLAB, i.e. approximately 2.2e-16.
  • 8. • So you type and get :
  • 9.
  • 10. • Logical Functions : x is a vector : Try these statements : x=1:5 any(x) any(x) : returns scalar 1 in ans if any element of x is nonzero.
  • 11. • Try for the o/p of x = [ 0 0] any(x) all(x) Returns scalar 1 if all elements of vector x r non zero! x=1:5; all(x) Try to get info abt all logic functions
  • 12.
  • 14. • For Basic i/p o/p of string we have : name = input( 'Enter your surname: ', 's' ); Chk the workspace Now type disp(name)