Is there a function in MATLAB that lets me find the first element of string cell array A
that also belongs to string cell array B
?
I'm currently using:
i = find(ismember(A,B));
string = A{i(1)};
But I'd like to know if there's a function that doesn't calculate ismember
until the last element of A
but rather stop when finding the first match. The reason is A
contains around 1,800,000 strings and I'm only interested in finding the first match.
Would a for
loop be faster if I did:
for j=1:length(A)
if ismember(A{j}, B)
string = A{j};
break
end
end
??
Does the number of elements in A
even influence the time required for calculating ismember
?
Thank you.
ismember(B,A)
? I don't know because I ignore exactly what happens insideismember
.Thank you! – ACenTe25A
is already "unique
" – ACenTe25