Convert a table column of mixed data type to one data type

1 visualización (últimos 30 días)
JFz
JFz el 16 de Jun. de 2016
Respondida: Kirby Fears el 16 de Jun. de 2016
Hi,
I have a table column that has both integers and strings. The integers are for dates. I would like to convert the integers to dates and then dates to strings.
How to do that?
Thanks in advance!
Jennifer
  1 comentario
James Tursa
James Tursa el 16 de Jun. de 2016
Please post a small example, showing exactly what you have in the column and what the desired output would be. Specifically, what is the integer value and how is it related to a date?

Iniciar sesión para comentar.

Respuestas (1)

Kirby Fears
Kirby Fears el 16 de Jun. de 2016
Jennifer,
Here's an example using a cell mixed type cell array "Var1" in table "t". You should be able to solve your problem with a similar approach.
t = cell2table({'date1',736495,'date2',736496,'date3',736497}');
ix = cellfun(@isnumeric,t.Var1);
t.Var1(ix) = cellfun(@(x)datestr(x,'yyyymmdd'),t.Var1(ix),'UniformOutput',false);

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by