How to convert categorical array contains 'yes' or 'no' to logical array?
25 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Bayu Ardiyanto
le 16 Avr 2018
Commenté : Bayu Ardiyanto
le 16 Avr 2018
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 commentaires
Jan
le 16 Avr 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.
Réponse acceptée
Steven Lord
le 16 Avr 2018
As stated in the documentation you can use the == operator to select elements in a categorical array that are in a particular category.
>> A = categorical({'yes','yes','no','no','yes','no'}) A = 1×6 categorical array yes yes no no yes no
>> A == 'yes' ans = 1×6 logical array 1 1 0 0 1 0
0 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Categorical Arrays dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!