Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Faster Method for removing duplicates

Asked by Adam on 29 Mar 2013

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]

0 Comments

Adam

Products

1 Answer

Answer by Cedric Wannaz on 29 Mar 2013
Edited by Cedric Wannaz on 29 Mar 2013
Accepted answer
 >> 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 Comment

Adam on 2 Apr 2013

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.

Cedric Wannaz

Contact us