find function
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Chiara Modenese
am 27 Mär. 2011
Beantwortet: Mohammad amiri
am 24 Nov. 2013
Hello,
can anyone enlighten me about the use of find() function? Is it really so bad in performance to use? Any alternative?
Thanks, Chiara
0 Kommentare
Akzeptierte Antwort
Matt Tearle
am 27 Mär. 2011
No. I'm guessing you are getting feedback from either humans or the MATLAB Code Analyzer about using logical indexing instead of find...? In that case, yes, that's true, but it depends on your application. If you really need indices, then use find. If, however, you're only using it to index into other arrays, skip find and just index directly. Eg instead of
idx = find(x > pi);
z = y(idx);
do
idx = x > pi;
z = y(idx);
Similarly, if you just want to know how many values satisfy some criterion, use nnz rather than numel(find(...))
Bottom line: there's nothing wrong with find if you really want to find indices. But if it's really just an intermediate step to something else, there are often neater ways to get there.
Weitere Antworten (3)
Walter Roberson
am 27 Mär. 2011
logical indexing is often an alternative to find.
Performance -- it depends what you are trying to do. For some problems there are more efficient solutions. For example if relatively few of the elements are non-zero, then using sparse matrices might be productive. (Note: if you do use sparse matrices, then find() gets used even more often, but is quite efficient.)
0 Kommentare
jasprit kour
am 27 Mär. 2011
find function only gives you the index of the value u want to find. there is also option you can also get the row and column index and and you only get the non-zero values.
0 Kommentare
Mohammad amiri
am 24 Nov. 2013
for 2D matrix you can write: a=rand(10,10); [r,c]=find (a>0.5); return the row and column of matrix witch is greater than 0.5
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!