how to find index of string using AND operator when adding conditions
3 views (last 30 days)
Show older comments
I want to search in a string matrix zz for index of 'A' in a cell when the value of the other cell is 'B'.
using idx = find(ismember(zz, 'A')); I can only get the index A
but i need to know the index of A only if the value of the other cell in another cloumn is B
something like this
idx = find(ismember((zz, 'A')&& (zz,'B')));
Thanks,
Roxan
0 Comments
Accepted Answer
Stephen23
on 13 Aug 2020
Edited: Stephen23
on 13 Aug 2020
>> zz = {'2','B','A';'2','C','A';'2','V','H';'2','B','Y';'3','F','A';'3','G','A';'3','B','A';'2','G','A'}
zz =
'2' 'B' 'A'
'2' 'C' 'A'
'2' 'V' 'H'
'2' 'B' 'Y'
'3' 'F' 'A'
'3' 'G' 'A'
'3' 'B' 'A'
'2' 'G' 'A'
>> idx = find(strcmp(zz(:,2),'B')&strcmp(zz(:,3),'A'))
idx =
1
7
More Answers (1)
Bruno Luong
on 13 Aug 2020
Edited: Bruno Luong
on 13 Aug 2020
Your description is not clear to me so I give two versions
idx = find(ismember(zz, {'A' 'B'}));
or
idx = find(ismember(zz, 'A') & ismember(xx, 'B'));
See Also
Categories
Find more on Cell Arrays 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!