How to efficiently find a string in a cell array
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Walter Roberson
il 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.
0 Commenti
Vedere anche
Categorie
Scopri di più su Operators and Elementary Operations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!