How to run find function faster?
古いコメントを表示
Dear All,
I have an array A with 6000 elements in integers, for example, "10", "12", "5" and others. Actually array A saves the number of non-zero elements in each rows of a sparse matrix B. I want to do some calculations on those selected rows in B with certian number of non-zero elements. I want to find out the indecis of selected values "10", "12" and "5" in A.
I did the following:
[~,ind1] = find(A==10);
[~,ind2] = find(A==12);
[~,ind3] = find(A==5).
I found it took about 1 second which is too slow. I am wondering if there is a faster way to do this
Thanks a lot.
Benson
6 件のコメント
Stephen23
2021 年 6 月 28 日
"I am wondering if there is a faster way to do this"
It rather depends on what you are doing with those indices, which you did not tell us.
Benson Gou
2021 年 6 月 28 日
Stephen23
2021 年 6 月 28 日
As dpb already wrote, you should first try using (faster and more efficient) logical indexing, before using FIND.
James Tursa
2021 年 6 月 28 日
The overall goal isn't to make find( ) faster ... the overall goal is to make your code run faster. For that, we need to know what your overall code is doing. E.g., maybe there is a way to get your result without explicitly using find( ) at all. Please give us details about how you are using the results from find( ) downstream in your code.
Paul
2021 年 6 月 29 日
Is anyone else surprised that these three calls to find takes "about 1 second" for an 6000-element array of integers?
dpb
2021 年 6 月 29 日
Not without more details; "know nuthink!" of just how was timed or what was the platform.
Also, I've not compared, but that the A array is sparse could well be a factor as well...
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Standard File Formats についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!