How to efficiently find a string in a cell array
7 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Walter Roberson
on 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 Comments
See Also
Categories
Find more on Operators and Elementary Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!