How to efficiently find a string in a cell array

6 vues (au cours des 30 derniers jours)
Arnaud Courvoisier
Arnaud Courvoisier le 18 Mar 2019
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.

Réponses (1)

Walter Roberson
Walter Roberson le 18 Mar 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.

Catégories

En savoir plus sur Operators and Elementary Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by