Clear Filters
Clear Filters

Re: find()

3 views (last 30 days)
John Kim
John Kim on 6 Sep 2016
Answered: Star Strider on 6 Sep 2016
Dear all,
Hi, I have a question regarding find(). Does find() always return a vector containing the linear indices IN ASCENDING ORDER? I guess it does, but I cannot find documentation to that effect.
I'd much appreciate your help. Thanks very much!
Best,
John

Answers (2)

George
George on 6 Sep 2016
From what I can tell in the find documentation the answer is yes. The doc states that the find function "...returns the first n indices corresponding to the nonzero elements in X." (or if n is omitted it returns all of them)
The existence of the last directionallity argument further supports this by finding the last n elements.

Star Strider
Star Strider on 6 Sep 2016
It does, at least as I read the documentation.
The relevant part of the find documentation is the Linear Indices section. A link at the end of that page points you to Matrix Indexing and specifically to the section on Linear Indexing. This section discusses the way MATLAB stores and indexes vectors and matrices.
Note that this relates specifically to linear indexing of vectors and matrices. The find function allows you to return the row and column indices of a matrix as well, so what you get as a result depends on what you ask for.

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!