How to efficiently find a string in a cell array
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a cell array like so
A =
6×1 cell array
{'repump locking' }
{'unused laser' }
{'unused laser' }
{'cooler frequency'}
{'cooler power' }
{'repump power' }
and I which to find the position of the cell containing 'cooler power' for instance.
I now use
ismember(A,'cooler power')
but it is exceedingly slow for my application. Do you know any faster way to do that ?
Thank you,
Arnaud.
0 comentarios
Respuestas (1)
Walter Roberson
el 18 de Mzo. de 2019
In theory,
[~, idx] = ismember('cooler power', A);
should be faster. However in my testing it was not clear that it was any faster than
find(ismember(A, 'cooler power'))
What was faster was
find(strcmp(A, 'cooler power'))
or
find(strcmp('cooler power', A))
which I could not reliably distinguish between in timing.
0 comentarios
Ver también
Categorías
Más información sobre Operators and Elementary Operations 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!