change table var type
66 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
LO
el 8 de Feb. de 2021
Comentada: Jeremy Hughes
el 8 de Feb. de 2021
How can I change the variable type in a table from double to string ?
I found plenty of posts with the same issue but during import from excel. My table is already there and I need to change the var type of a column.
2 comentarios
Respuesta aceptada
Steven Lord
el 8 de Feb. de 2021
A = array2table(magic(4))
A.Var1 = string(A.Var1)
Though depending what you're trying to do, using discretize or categorical to create a categorical array might be a better option.
load patients
patients = table(LastName,Gender,Age,Height,Weight);
head(patients)
patients.AgeCategory = discretize(patients.Age, 0:10:100, 'categorical');
patients.Gender = categorical(patients.Gender);
head(patients)
0 comentarios
Más respuestas (1)
KALYAN ACHARJYA
el 8 de Feb. de 2021
Editada: KALYAN ACHARJYA
el 8 de Feb. de 2021
"My table is already there and I need to change the var type of a column."
If the data is numeric, you can use num2str(variable_name) to convert numeric var to string data type.
Lets suppose you have table variable T and want to convert string of the particular column variable "col1", then
num2str(T.col1)
2 comentarios
Jeremy Hughes
el 8 de Feb. de 2021
I think you should share your code. Hard to tell what you really need to do.
Ver también
Categorías
Más información sobre Tables en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!