option faster than unique?

12 次查看(过去 30 天)
Arti Siddhpura
Arti Siddhpura 2014-6-6
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