More efficient alternative to the find function?
Show older comments
Hi all,
I am working on a path planning algorithm. I have generated a matrix A (consists of 1s and 0s.) which stores the neighbor node information. Using the following code I am finding the available neighbors and storing them in vector F.
F = find(A(current,:)==1);
However, unfortunately I found out that this line of code takes the longest time in my code (from 0.004018 to 0.023119s). (A matrix is a 37901 by 37901 matrix.)
Is there a more computationally efficient method to do this?
Thanks!
This is what the A matrix looks like:

Accepted Answer
More Answers (1)
Walter Roberson
on 8 Mar 2018
You can improve a little by using
F = find(A(current,:));
Your A values are only 0 and 1, so comparing to 1 is going to give you exactly the same as A since == returns 0 and 1.
1 Comment
Canberk Suat Gurel
on 9 Mar 2018
Edited: Canberk Suat Gurel
on 9 Mar 2018
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!