Efficient method of searching cell array for multiple, partial (non exact) strings
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, internet!
I'm looking for the most efficient way to look through a cell array to match partial strings. I know I can bound things in a loop, but there has to be a more efficient method of doing this.
Given the following:
MasterList = {'dog' 'house' 'hotdog' 'cat' 'house music' 'banana' 'that actor from the 80s'};
SearchFor = {'dog' 'house' 'actor'};
I would like a search algorithm to return:
LogicalArrayX = 1 1 1 0 1 0 1
I know that partialLogicalArrayX = strfind(MasterList,SearchFor{i}) will return the character indices of MasterList when searching for SearchFor{i}, but I'd like it to return a logical matrix and be able to batch-process SearchFor instead of having to loop around the i variable.
Thanks!
0 Kommentare
Antworten (1)
Azzi Abdelmalek
am 1 Sep. 2016
Bearbeitet: Azzi Abdelmalek
am 1 Sep. 2016
edit
MasterList = {'dog' 'house' 'hotdog' 'cat' 'house music' 'banana' 'that actor from the 80s'};
SearchFor = {'dog' 'house' 'actor'};
LogicalArrayX=logical(~cellfun(@isempty,regexp(MasterList,'dog|house|actor','once')))
2 Kommentare
Azzi Abdelmalek
am 1 Sep. 2016
Bearbeitet: Azzi Abdelmalek
am 1 Sep. 2016
MasterList = {'dog' 'house' 'hotdog' 'cat' 'house music' 'banana' 'that actor from the 80s'};
SearchFor = {'dog' 'house' 'actor'};
patern= strjoin(SearchFor,'|')
LogicalArrayX=logical(~cellfun(@isempty,regexp(MasterList,patern,'once')))
Siehe auch
Kategorien
Mehr zu Clocks and Timers finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!