EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials Matlab Tutorial Find Function Matlab
 

Find Function Matlab

Priya Pedamkar
Article byPriya Pedamkar

Updated March 24, 2023

find function matlab

 

 

Introduction to Find Function Matlab

MATLAB provides its user with a basket of functions, in this article we will understand a powerful function called ‘Find’. In its simplest form, find function will return the indices of array X that points to the nonzero elements. If it finds none, the function will return an empty matrix.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Syntax of Find Function:

  1. R = find(X)
  2. R = find (X, n)
  3. R = find (X, n,direction)
  4. [row, col] = find ()
  5. [row, col, v] = find ()

Description of Find in Matlab

Below will learn all the Find function in Matlab one by one accordingly:

1. R = find(A)

  • Here A is an array, this function will return a vector that will contain linear indices of each non zero elements of A.
  • Let’s assume A to be a vector then R will return a vector which will have the same orientation as x.
  • If A is to be a multidimensional array, R will give back a column vector containing linear indices.
  • If A has all zeros or empty values, then R will give us an empty array.

Let us now understand this concept with an example:

Here, X is a 3 x 3 matrix:

Code:

X = [2 1 1; 0 3 1; 0 0 1] k = find(X)

Below is how the console will look like:

Output:

R = find(A)

Let us use a logical operator ~ to locate the zero values.

Code:

X = [2 1 1; 0 3 1; 0 0 1] R1 = find(~X)\

Output:

Find Function Matlab - 1.1

2. R = find (X, n)

This function will return the first n indices for the non zero values in X. Below is an example to understand this find function:

X is a 3 x 3 matrix:

Code:

X=[8 1 6;3 5 7;4 9 2] k = find(X < 10, 5)

Output:

R = find (X, n)

3. R = find (X, n,direction)

This function will return the n indices for non zero elements in either last or first direction as specified in the function. Below is an example to understand this find function:

Code:

X is a 3 x 3 matrix:

X=[0 1 0;3 0 7;0 9 0] k = find (X, 3, last)

Output:

Find Function Matlab - 3

4. [row, col] = find()

This function will return the row and column subscripts of non zero elements of array X for any of the above-mentioned functions. Below is an example to understand this find function:

Code:

X is a 3 x 3 matrix:

X=[1 3 1;8 0 1;5 4 6] [row, col] = find(X>0 & X<5, 3)

Output:

[row, col] = find()

5 . [row, col, v] = find()

This function will return vector ‘v’ in addition to the row and column subscripts of non zero elements of array X for any of the above-mentioned functions. Below is an example to understand this find function:

Code:

X is a 3 x 3 matrix:

X=[1 3 0;8 0 1;0 4 0] [row, col, v] = find(X)

Output:

Find Function Matlab -5

Conclusion

We can find elements of arrays that satisfy a defined condition. For achieving this, we need to use find function along with a relational expression. So, find(A<4) will return linear indices of the elements of A which are less than 4. We can also directly find elements in A that fulfill the given condition like A<5. For this, we simply use A(A<5). Here we can avoid making calls to function like A(find(A<5)) When we execute find function with any relational operation like A>1, we must remember that here, the result will be a matrix of 1s & 0s. Example: [row, col, A] = find(A>1) will return column vector with logical true values.

Recommended Articles

This is a guide to Find Function Matlab. Here we discuss the introduction and description of find in Matlab with proper codes and outputs. You can also go through our other related articles to learn more –

  1. Matlab Create Function
  2. Matlab Logical Operators
  3. MATLAB Functions
  4. Piecewise Function in Matlab
  5. How to Use Comet() Method in Matlab

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW