MATLAB: Counting occurrence of matched strings in multiple columns

matched stringsoccurrence

Hi:
Give that: TN = {Hex1}, DS= {Hex15, Hex16… Hex20}, Names= { Hi, Hello}. I want to count the occurrence of the matched strings from column A,B, and E of the string Hi with any of the elements in DS with the element in TN. I should have 2 occurrences as shown in the attached file (highlighted in Blue). Thanks!

Best Answer

One possible solution would be like this.
TN = {'Hex1'};
DS = {'Hex15','Hex16','Hex17','Hex18','Hex19','Hex20'};
[~,txt] = xlsread('Myfile.xls');
idx =...
ismember(txt(:,1),TN) &...
ismember(txt(:,2),DS) &...
strcmp(txt(:,5),'Hi');
The result is:
>> txt(idx,:)
ans =
2×5 cell array
{'Hex1'} {'Hex15'} {0×0 char} {0×0 char} {'Hi'}
{'Hex1'} {'Hex20'} {0×0 char} {0×0 char} {'Hi'}