How to efficiently find a string in a cell array

7 Ansichten (letzte 30 Tage)
Arnaud Courvoisier
Arnaud Courvoisier am 18 Mär. 2019
Beantwortet: Walter Roberson am 18 Mär. 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.

Antworten (1)

Walter Roberson
Walter Roberson am 18 Mär. 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.

Kategorien

Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by