Difference between 'cell' and 'string'

15 visualizaciones (últimos 30 días)
alpedhuez
alpedhuez el 7 de Dic. de 2020
Comentada: alpedhuez el 8 de Dic. de 2020
I readtable two csv files that both includes months (January, February,...). In one file, they are string. In the other file, they are cell. Will it be better to have these name of the months as string or as cell?

Respuesta aceptada

Walter Roberson
Walter Roberson el 7 de Dic. de 2020
It depends what you are going to do with them.
readtable() has an option about which one to return.
Based on your other questions I suspect that for your purposes that categorical() might be best for presentation reasons.
If you are converting to datetime then sometimes string is easier as the + string concatenation operator is nice for putting together string fragments.
  4 comentarios
Walter Roberson
Walter Roberson el 8 de Dic. de 2020
Also, if you have a datetime variable in a table, you can set its Format property to change how it will display.
alpedhuez
alpedhuez el 8 de Dic. de 2020
Thank you.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 7 de Dic. de 2020
In addition to what the others have said, see the FAQ for a good intuitive description of what a cell array is.
Your CSV file will not be strings in one and cells in the other CSV file. They are just regular, normal flat text files. Strings, character arrays, and cell arrays are a concept internal to MATLAB and your flat text CSV files have no idea about that. Whether they end up as
  1. a cell array of character arrays, or
  2. an array of strings
inside MATLAB depends entirely on how (what function) you use to read them into MATLAB. readtable() will make them whatever data type it decides to make them, and just use them like that. I don't see any need to change what readtable() decided to do.

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!

Translated by