Letter to numerb: Create a new 'if' variable to change 'Y' and 'N' to 1 and 0

조회 수: 2 (최근 30일)
Max
Max 2022년 8월 14일
편집: dpb 2022년 8월 14일
I would like to create a new variable and change those 'N's and 'Y's to 0 (N) and 1 (Y).
Does someone know an easy way to solve the problem?
Best regards
Max

답변 (1개)

dpb
dpb 2022년 8월 14일
>> categorical({'Y';'N';'Y'},{'N';'Y'},{'0';'1'})
ans =
3×1 categorical array
1
0
1
>> matches({'Y';'N';'Y'},'Y')
ans =
3×1 logical array
1
0
1
>> categorical(matches({'Y';'N';'Y'},'Y'))
ans =
3×1 categorical array
true
false
true
>>
  댓글 수: 2
Max
Max 2022년 8월 14일
I´m not able to use it in my editor..
dpb
dpb 2022년 8월 14일
편집: dpb 2022년 8월 14일
What does that mean, pray tell? What is "it" and what are you trying to accomplish?
Above is three slightly different approaches to converting a string variable Y/N to a logical one...
BTW, there's no data in the attached spreadsheet that shows anything that appears to be at all related to the question asked...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by