How can i replace a string to a numeric value in a specific column of an array ?

3 views (last 30 days)
I have a data set od cancer diagnosis and the data has a column of strings B and M for benign and malignant cancer cells(for 'n' no.of patients). I want to replace the letters with 0s and 1s. Is there a function in matlab to do this replacing? If no can someone help with the code. Would be much appreciated!

Answers (1)

Star Strider
Star Strider on 24 Oct 2021
I am not certain if ‘string’ refers to character vectors or string variables.
Try this —
column = ['M';'B';'M';'M';'B';'B']
column = 6×1 char array
'M' 'B' 'M' 'M' 'B' 'B'
g = findgroups(column)-1
g = 6×1
1 0 1 1 0 0
.

Community Treasure Hunt

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

Start Hunting!