7.10: The find() function (2024)

  1. Last updated
  2. Save as PDF
  • Page ID
    87696
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}}}\)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{#1}}} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}}}\)

    \( \newcommand{\vectorC}[1]{\textbf{#1}}\)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}}\)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}}\)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}}}\)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{#1}}} \)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)

      The MATLAB built-in function find() is an efficient method to find the indices of data that satisfy some logical condition.

      The syntax of the find function is:

      indx = find( condition )

      The output of the find() function is the set of indices for which the "condition" is true.

      This is illustrated by these examples:

      Example \(\PageIndex{1}\) find() with an == condition

      a = 1:0.5:4 % a = [1.0 1.5, 2.0, 2.5, 3.0, 3.5, 4.0]
      idx1 = find(a == 3.0) % Find the elements equal to 3 and return their indices
      % idx1 = 5, becuz the 5th element of a is 3.0

      % Check it with this code
      a_idx1 = a(idx1) % = 3.0

      Solution

      Add example text here.

      .

      Example \(\PageIndex{2}\) find() with a < condition

      a = 1:0.5:4 % Same vector as above
      idx2 = find(a < 3.0)
      % idx = 1 2 3 4
      % These are the indices of the elements of a < 3

      % Check it with this code
      a(idx2) % = 1.0, 1.5, 2.0, 2.5

      Solution

      Add example text here.

      .

      Example \(\PageIndex{3}\) find() with a compound condition

      a = 1:0.5:4 % Same vector as above
      % Find the indices of the elements between 2.0 and 3.5, inclusive
      % We need to use a compound conditional expression
      idx3 = find( (2.0 <= a) & (a <= 3.5) )
      % "&" = "and"
      % That means that for a particular value of a, both conditional parts have to be true for
      % for the compound conditional to be true.
      % idx3 = 3 4 5 6
      % These are the indices of the elements that satisfy both parts

      % Check it with this code

      a(idx3) % = 2.0, 2.5, 3.0, 3.5

      Solution

      Add example text here.

      .

      Example \(\PageIndex{4}\) The result of the compound condition itself

      %% The condition by itself:
      ( (2.0 <= a) & (a <= 3.5) )
      %ans =
      % 1×7 logical array
      % 0 0 1 1 1 1 0
      % 0= False for the elements that do not satisfy both parts of the
      % conditional
      % 1=True for the elements that do satisfy both parts

      Solution

      Add example text here.

      .

      Example \(\PageIndex{5}\) What could go wrong?

      %% What happens if we try this?
      % A single condition, instead of a compound condition:
      idx3b = find(2.0 <= a <= 3.5)

      % The result is: idx3b = 1 2 3 4 5 6 7 (!?)
      % This is clearly not what was desired.

      % The condition by itself (2.0 <= a <= 3.5) returns:
      % 1 1 1 1 1 1 1
      % becuz every value of a is either >= 2 or <= 3.5
      % You can only have a comparison between 1 number and 1 variable
      % or 2 variables.
      % You need to have each part of the compound be a complete condition by itself, as above, namely:

      % ( (2.0 <= a) & (a <= 3.5) )

      Solution

      Add example text here.

      .

      Example \(\PageIndex{6}\) find() with 2 variables

      a = 1: 0.5 :4 % As above
      b = 2
      idx4 = find(b == a)
      % idx4 = 3
      a(idx4) % 2

      Solution

      Add example text here.

      .

      Example \(\PageIndex{7}\) find() with no match.

      When there are no elements that satisfy the condition,

      then the find() command returns an empty vector.

      a = 1:0.5:4
      b = 20
      idx4 = find(b == a)

      % idx4 = empty

      Solution

      Add example text here.

      .

      Example \(\PageIndex{8}\)

      %% Example 5: 2 vectors of the same length
      a = 1:0.5:4
      % a = [1.0 1.5, 2.0, 2.5, 3.0, 3.5, 4.0]
      c = [ 0 1 2 3 4 5 6 ]
      idx5 = find( a == c)
      % idx5 = 3, because a(3) = b(3) = 2
      % Also, even though both vectors have values of 1, 3, and 4
      % these don't occur in the same place, so they are not matches.

      Solution

      Add example text here.

      .

      Exercise \(\PageIndex{1}\) Test Scores >= 90

      % Use these test scores:
      test_scores = [
      73
      72
      88
      94
      77
      92
      88
      65
      86
      78
      97
      65]
      % Use the find() function to find and list the test scores >= 90

      Answer

      Add texts here. Do not delete this text first.

      .

      7.10: The find() function (2024)

      References

      Top Articles
      Clasificados Renta Miami Efficiency
      Money blog: Bakery chain under fire for selling day-old croissants for 95p more
      Yogabella Babysitter
      Nyu Paralegal Program
      Erika Kullberg Wikipedia
      Weekly Math Review Q4 3
      Blue Beetle Showtimes Near Regal Swamp Fox
      Accuradio Unblocked
      Craigslist Panama City Fl
      Extra Virgin Coconut Oil Walmart
      Gemita Alvarez Desnuda
      Equibase | International Results
      1v1.LOL - Play Free Online | Spatial
      Craigslist Pinellas County Rentals
      Sussyclassroom
      Sef2 Lewis Structure
      Mtr-18W120S150-Ul
      Seeking Arrangements Boston
      27 Paul Rudd Memes to Get You Through the Week
      Sec Baseball Tournament Score
      Powerschool Mcvsd
      Cb2 South Coast Plaza
      Bay Area Craigslist Cars For Sale By Owner
      Helpers Needed At Once Bug Fables
      Buhl Park Summer Concert Series 2023 Schedule
      What we lost when Craigslist shut down its personals section
      Log in or sign up to view
      FREE Houses! All You Have to Do Is Move Them. - CIRCA Old Houses
      UPC Code Lookup: Free UPC Code Lookup With Major Retailers
      Armor Crushing Weapon Crossword Clue
      Wake County Court Records | NorthCarolinaCourtRecords.us
      Orange Pill 44 291
      Composite Function Calculator + Online Solver With Free Steps
      American Bully Xxl Black Panther
      Low Tide In Twilight Manga Chapter 53
      Lcwc 911 Live Incident List Live Status
      Immobiliare di Felice| Appartamento | Appartamento in vendita Porto San
      Hazel Moore Boobpedia
      Pink Runtz Strain, The Ultimate Guide
      Vintage Stock Edmond Ok
      Spurs Basketball Reference
      Breaking down the Stafford trade
      Hawkview Retreat Pa Cost
      Costco The Dalles Or
      Boyfriends Extra Chapter 6
      Benjamin Franklin - Printer, Junto, Experiments on Electricity
      Lebron James Name Soundalikes
      Freightliner Cascadia Clutch Replacement Cost
      Here’s What Goes on at a Gentlemen’s Club – Crafternoon Cabaret Club
      Diamond Desires Nyc
      Autozone Battery Hold Down
      Ssss Steakhouse Menu
      Latest Posts
      Article information

      Author: Clemencia Bogisich Ret

      Last Updated:

      Views: 5999

      Rating: 5 / 5 (60 voted)

      Reviews: 83% of readers found this page helpful

      Author information

      Name: Clemencia Bogisich Ret

      Birthday: 2001-07-17

      Address: Suite 794 53887 Geri Spring, West Cristentown, KY 54855

      Phone: +5934435460663

      Job: Central Hospitality Director

      Hobby: Yoga, Electronics, Rafting, Lockpicking, Inline skating, Puzzles, scrapbook

      Introduction: My name is Clemencia Bogisich Ret, I am a super, outstanding, graceful, friendly, vast, comfortable, agreeable person who loves writing and wants to share my knowledge and understanding with you.