Faster Method for removing duplicates

4 次查看(过去 30 天)
I am trying to remove duplicate nodes from an auto mesh. I have attached a simple script. This works, but takes FOREVER if there are many (greater than 10,000) nodes. Does anyone have an alternate suggestion that would be faster?
node =
[0.1234 5.6789;
3.4567 9.8765;
4.5678 8.7654;
0.1234 5.6789]
% Remove duplicate nodes
node_array=cell(1,length(node));
for j = 1:length(node)
node_array(j,1) = {node(j,:)};
end
node_array_cat = cat(1,node_array{:});
[node junk node_map] = unique(node_array_cat,'rows');
node =
[0.1234 5.6789;
3.4567 9.8765;
4.5678 8.7654]

采纳的回答

Cedric
Cedric 2013-3-29
编辑:Cedric 2013-3-29
>> node_u = unique(node, 'rows', 'stable')
node_u =
0.1234 5.6789
3.4567 9.8765
4.5678 8.7654
should be more efficient. What was the purpose of this conversion to cell array?
  1 个评论
Adam
Adam 2013-4-2
Thanks, I guess I should have been more specific. I need the node_map value as well. Regardless, I coded this a few years ago when I just started with MATLAB I am sure I found an example that was an array and just ran with it. You were correct, I did not need the array for my specific case and you have saved me much needed processing time. Thanks.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by