Speed up search for matching strings
古いコメントを表示
The following code works, but I would like to make if faster. Here, bowl_nodes and tmp_nodes are 1D arrays of the same size. Assume size(bowl_nodes) = size(tmp_nodes) = 1000. node_string is a string array. Each string in bowl_nodes matches with one and only one string in tmp_nodes. For example, the string in node_string( bowl_node(1) ) could be the same as the string in node_string( tmp_node(5) ). When matching strings are found, node_match stores the matching array indices and the element in tmp_nodes is removed. This way, every time the for-loop over m executes, it executes over fewer elements. When the code is done executing, tmp_nodes is empty. Can anyone recommend a way to speed up this code? The code's purpose is to fill up the node_match array, which links elements of bowl_nodes to elements of tmp_nodes and visa versa. (Note: tmp_nodes is a copy of a different array, so even though tmp_nodes gets removed by this code, the original array is still intact and is used later in the program.) Thanks.
for n= 1:size( bowl_nodes)
for m= 1:size( tmp_nodes)
if node_string( bowl_nodes(n) ) == node_string( tmp_nodes(m) )
node_match ( bowl_nodes(n) ) = tmp_nodes(m);
node_match ( tmp_nodes(m) ) = bowl_nodes(n);
tmp_nodes(m)= [];
break;
end
end
end
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!