フィルターのクリア

How to change character in multiple cells in to number 0 and 1?

2 ビュー (過去 30 日間)
Wenyi Xiao
Wenyi Xiao 2019 年 4 月 19 日
回答済み: Wenyi Xiao 2019 年 4 月 19 日
I've got an excel file which contains a column for sex,'F' and 'M'. 'F' means female and 'M' means male. I used xlsread() to load this data, and got multiple cells( size is 1*n,n for number of people), each cell contains a character 'F' or 'M'. I want to transfer the character to number 0 or 1, 0 means 'F' and 1 means 'M'. How can I do it?

採用された回答

Jos (10584)
Jos (10584) 2019 年 4 月 19 日
Sex = {'F','M','F','F','M','M','F'}
[~, SexNum] = ismember(Sex, {'F','M'})
SexNum = SexNum - 1 % 1 = 'M', 0 = 'F', -1 = other
% alternatively
SexNum2 = cellfun(@(c) double(c=='M')), Sex) % 1 is 'M', 0 = 'F' or other)
  1 件のコメント
Wenyi Xiao
Wenyi Xiao 2019 年 4 月 19 日
It works!!!!!!!!! Thank you so much!

サインインしてコメントする。

その他の回答 (1 件)

Wenyi Xiao
Wenyi Xiao 2019 年 4 月 19 日
S = findgroups(Sex);
I used this code, it works too!!!!!
Thank you!

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by