Reputation: 143
I have a string array
sub_str = {'SN1','SN2'}; main_str = {'SN3','SN2','SN1','SN4'};
i would expect output (the index) for the sub_str in main string is [3 2]. Is there a one liner to this?
Upvotes: 0
Views: 46
Reputation: 221514
Use second output argument from ismember -
ismember
Code
[~,ind] = ismember(sub_str,main_str)
Output
ind = 3 2
You can also use intersect -
intersect
[~,~,ind] = intersect(sub_str,main_str)
Upvotes: 1