How to convert categorical array contains 'yes' or 'no' to logical array?
Show older comments
Hi, I have a table consist of categorical array which is just contains 'yes' and 'no', ex:
a = [yes yes no no yes no]
I want to convert it to a logical array translating yes to 1 and no to 0. ex:
b = [1 1 0 0 1 0]
Could you show me the way to do it? Thanks!
2 Comments
Jan
on 16 Apr 2018
What is the type of your variable "a"? a = [yes yes no] is not valid Matlab code. Please post some code, which creates your input data. This is better than a rough description by words.
Bayu Ardiyanto
on 16 Apr 2018
Accepted Answer
More Answers (1)
KSSV
on 16 Apr 2018
a = {'yes' 'yes' 'no' 'no' 'yes' 'no'} ;
b = strcmp(a,'yes')
Categories
Find more on Categorical Arrays in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!