Clean way to find which elements of categorical array are part of a set of labels
    4 views (last 30 days)
  
       Show older comments
    
    Daniel Armyr
 on 8 Feb 2016
  
    
    
    
    
    Answered: David Sanchez
      
 on 8 Feb 2016
            Hi. I have a categorical array. I want to find which elements belong to a set of labels. Here is an example of what I would like to write, but I obviously need some form of function here.
data = nominal( {'a', 'b', 'c', 'b', 'a'} )'
%This line will in fact not work, so I am looking for a clean way to write it.
isAorB = any(data == {'a', 'b'});
disp( isAorB );
1
1
0
1 
1
0 Comments
Accepted Answer
  David Sanchez
      
 on 8 Feb 2016
        I think you are looking for this:
data = {'a', 'b', 'c', 'b', 'a'} ;
members = {'a','b'};
ismember(data,members)
ans =
       1     1     0     1     1
0 Comments
More Answers (0)
See Also
Categories
				Find more on Categorical 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!
