option faster than unique?
조회 수: 12 (최근 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
답변 (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에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!