option faster than unique?
4 ビュー (過去 30 日間)
古いコメントを表示
I am working on a 955*1 double vector xy where I need to generate it 101 times and once generated, each time I need to remove repeating elements from it, sort in ascending order and get index of remaining elements. I am using unique for this. (i.e.[xyuni, ind] = unique( xy );) This operation takes almost 2 sec. I need to make this faster. For that, I tried to use intersect but it is slower than unique. I downloaded count_unique from http://www.mathworks.com.au/matlabcentral/fileexchange/23333-determine-and-count-unique-values-of-an-array. But this only removes repeating elements and sorts but does not provide index. I tried tip from http://www.mathworks.com/matlabcentral/answers/127660-how-would-i-create-my-own-unique-function-without-using-the-built-in-unique and created myUnique using sort but again it does not provide index. Please let me know if there exist any other option to make this operation faster. Many thanks.
1 件のコメント
Uday
2015 年 4 月 20 日
Can you paste the data and the code to visualize what you are trying to explain ?
回答 (1 件)
Sean de Wolski
2015 年 4 月 20 日
編集済み: Sean de Wolski
2015 年 4 月 20 日
Perhaps I'm missing something but on my machine (fairly wimpy laptop) this is taking a few hundredths of a second
tic
for ii = 1:100
[uv,id] = unique(randi(400,1000,1));
end
toc
Elapsed time is 0.013925 seconds
So I doubt unique is the bottleneck and even if it is, I doubt you'll find a faster solution without C or Fortran hardwired to your inputs. Have you profiled your code?
docsearch profile code
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!