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 vectors
• 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
Logical vectors
• 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

PPTX
Binary search
PPTX
Basic python part 1
PDF
Algorithms Lecture 6: Searching Algorithms
PDF
201801 CSE240 Lecture 21
ODP
Introduction to FreeMat
PDF
Skip Graphs and its Applications
PPTX
Tools for reading papers
PPTX
Algorithm & data structures lec4&5
Binary search
Basic python part 1
Algorithms Lecture 6: Searching Algorithms
201801 CSE240 Lecture 21
Introduction to FreeMat
Skip Graphs and its Applications
Tools for reading papers
Algorithm & data structures lec4&5

What's hot (20)

PPTX
Divide and conquer 1
DOCX
Best,worst,average case .17581556 045
PDF
Functions lect
PPTX
Data structures and algorithms
PDF
Lecture4
PPTX
Counting sort
PPT
L10 sorting-searching
PPT
Counting Sort Lowerbound
PDF
Binary Search - Design & Analysis of Algorithms
PPTX
Counting sort
PPT
Algorithms with-java-advanced-1.0
PPTX
Python decision making_loops_control statements part9
PPTX
Arrays.pptx
PPT
Matlab on basic mathematics
PPTX
MATLAB - Arrays and Matrices
PPTX
Insertion sort algorithm power point presentation
PPT
Big oh Representation Used in Time complexities
PDF
Sorting Algorithms
PPT
Sorting & Linked Lists
PPTX
Big o notation
Divide and conquer 1
Best,worst,average case .17581556 045
Functions lect
Data structures and algorithms
Lecture4
Counting sort
L10 sorting-searching
Counting Sort Lowerbound
Binary Search - Design & Analysis of Algorithms
Counting sort
Algorithms with-java-advanced-1.0
Python decision making_loops_control statements part9
Arrays.pptx
Matlab on basic mathematics
MATLAB - Arrays and Matrices
Insertion sort algorithm power point presentation
Big oh Representation Used in Time complexities
Sorting Algorithms
Sorting & Linked Lists
Big o notation
Ad

Viewers also liked (20)

PPTX
Michaelpritchard
PPTX
PDF
ODP
Improving your driveway, path or patio.
PPTX
Michaelpritchard
PPT
PPS
Fb Nnew Pps
PPT
Matlab graphics
PPT
SIB Green IT Policy
PDF
BarCamp in Saigon
PDF
Introduction into GIT
PPT
An approach to implement model classes in zend
PDF
Los espacios en la BECREA. junta de andalucía.
PDF
Servicios tradicionales en la BECREA
PPT
How to apply Agile in Marketing
PDF
GUÍA DE BIBLIOTECAS ESCOLARES. 6. Extensión cultural. Director: José García G...
PPT
Client Satisfaction as engine of the continuous improvement
Michaelpritchard
Improving your driveway, path or patio.
Michaelpritchard
Fb Nnew Pps
Matlab graphics
SIB Green IT Policy
BarCamp in Saigon
Introduction into GIT
An approach to implement model classes in zend
Los espacios en la BECREA. junta de andalucía.
Servicios tradicionales en la BECREA
How to apply Agile in Marketing
GUÍA DE BIBLIOTECAS ESCOLARES. 6. Extensión cultural. Director: José García G...
Client Satisfaction as engine of the continuous improvement
Ad

Similar to Logical vectors (20)

PPTX
2. Chap 1.pptx
PDF
Matlab practical ---4.pdf
PPTX
Advance algebra
PDF
A MATLAB project on LCR circuits
PPT
bisection method
PPTX
MATLAB for Engineers ME1006 (1 for beginer).pptx
PPTX
mathhnbvnbvnvnhjhnvnvngvbcvbcvbvbvbvnbvnbvnb
PPT
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
PPTX
Presentación grupo 551108 30
PPTX
Exponents
PPT
Introduction to Matlab - Basic Functions
PDF
Matlab for marketing people
PDF
Domain and range (linear, quadratic, rational functions)
PDF
DOCX
PPS 7.7 RECURSION, AS A DIFFERENT WAY OF SOLVING PROBLEMS. EXAMPLE PROGRAMS
PDF
Dsp manual completed2
PPTX
Functions lesson
PDF
chapter1.pdf ......................................
PPTX
3_Q1-General-Mathematics.pptx lesson 3 for grade 11
PPT
Matlab1
2. Chap 1.pptx
Matlab practical ---4.pdf
Advance algebra
A MATLAB project on LCR circuits
bisection method
MATLAB for Engineers ME1006 (1 for beginer).pptx
mathhnbvnbvnvnhjhnvnvngvbcvbcvbvbvbvnbvnbvnb
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
Presentación grupo 551108 30
Exponents
Introduction to Matlab - Basic Functions
Matlab for marketing people
Domain and range (linear, quadratic, rational functions)
PPS 7.7 RECURSION, AS A DIFFERENT WAY OF SOLVING PROBLEMS. EXAMPLE PROGRAMS
Dsp manual completed2
Functions lesson
chapter1.pdf ......................................
3_Q1-General-Mathematics.pptx lesson 3 for grade 11
Matlab1

Recently uploaded (20)

PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
My India Quiz Book_20210205121199924.pdf
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
Trump Administration's workforce development strategy
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PPTX
20th Century Theater, Methods, History.pptx
PDF
advance database management system book.pdf
PPTX
TNA_Presentation-1-Final(SAVE)) (1).pptx
PPTX
Computer Architecture Input Output Memory.pptx
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
What if we spent less time fighting change, and more time building what’s rig...
Uderstanding digital marketing and marketing stratergie for engaging the digi...
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
My India Quiz Book_20210205121199924.pdf
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Trump Administration's workforce development strategy
Weekly quiz Compilation Jan -July 25.pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
20th Century Theater, Methods, History.pptx
advance database management system book.pdf
TNA_Presentation-1-Final(SAVE)) (1).pptx
Computer Architecture Input Output Memory.pptx
FORM 1 BIOLOGY MIND MAPS and their schemes
Paper A Mock Exam 9_ Attempt review.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 :
  • 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
  • 14. • For Basic i/p o/p of string we have : name = input( 'Enter your surname: ', 's' ); Chk the workspace Now type disp(name)