Find index of cell values in another cell array without a loop
32 views (last 30 days)
Show older comments
Hi all,
I have 2 cell arrays. Cell array B is always smaller than A and its values are always contained in A.
I want to find the indexes of each value contained in B within A.
Here is what I have with a loop and it works.
A = {'Q' 'W' 'E' 'R' 'T' 'Y' 'U' 'I' 'O' 'P'};
B = {'W' 'R' 'O'};
for i=1:length(B)
Index(i) = find(strcmpi(A,B(i)));
end
I want to remove the loop for efficiency purposes.
What would you suggest?
Thanks,
0 Comments
Accepted Answer
Akira Agata
on 3 Nov 2024 at 3:24
A = {'Q' 'W' 'E' 'R' 'T' 'Y' 'U' 'I' 'O' 'P'};
B = {'W' 'R' 'O'};
[~, index] = ismember(B, A)
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements 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!