필터 지우기
필터 지우기

option faster than unique?

조회 수: 12 (최근 30일)
Arti Siddhpura
Arti Siddhpura 2014년 6월 6일
편집: Sean de Wolski 2015년 4월 20일
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
Uday 2015년 4월 20일
Can you paste the data and the code to visualize what you are trying to explain ?

댓글을 달려면 로그인하십시오.

답변 (1개)

Sean de Wolski
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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by