Searching for a string in a very efficient way
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi.
I have two cell arrays, A and B. A contains 3000 strings and B contains 107,000 strings. Some of the strings in B might also be present in A. Each of these strings is a 7 letter word. I need to find which strings in B are also present in A. I did this by writing the following:
[~,p] = ismember(A, B);
p(p==0) = []; % removing zeros from the p array
I then use the indices in p to get the strings in B that are also in A. This works but takes a long time to compute (0.4 sec). Since I need to do this step about 30 times (for other A and B), the overall time becomes large. Does anyone have an idea of how to make this string search faster. With thanks in advance, G
0 comentarios
Respuesta aceptada
Azzi Abdelmalek
el 17 de Jul. de 2013
Editada: Azzi Abdelmalek
el 17 de Jul. de 2013
Instead of ismember(B, A), You should use
ismember(A,B);
Más respuestas (1)
Jan
el 17 de Jul. de 2013
ismember sorts the input strings to allow for an efficient binary search. If you call this 30 times, sorting the larger cell string explicitly will save 29 sorting procedures.
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!