How can i find indexes of multiple strings from a cell array?

5 views (last 30 days)
I have a cell aray A (100,000X1) in which every cell contains a string. I have another cell array B (10000x1) of same kind. I want to find the indexes of A which contains a specific string from B and i want to repeat that for every element of B.
I used the following function to find out the indexes for one element of B at a time. say hhh is the first element of B.
idx = find(ismember(A, 'hhh'))
I can't seem to define a variable in place of 'hhh' so that it can change for each element of B. What should I do?
Thank you.

Accepted Answer

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 20 Sep 2019
hi,
Here is one plain answer;
% Search string:
STR = 'hhh';
% Index finding:
IndexFind = strfind(A, STR);
Index = find(not(cellfun('isempty', IndexFind)));
% display the found strings containing STR
A{Index} %#ok
%%

More Answers (0)

Community Treasure Hunt

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

Start Hunting!