Change date InputFormat across a cell
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
BN
el 3 de Nov. de 2022
Respondida: Walter Roberson
el 3 de Nov. de 2022
Dear all,
How to change datetime format of this attached cell arrays from 1/1/1989 to 1989-1-1?
Here is my try, but it doesnt worked:
d = cellfun(@(OBS_MAX) datetime(OBS_MAX, 'InputFormat', 'yyyy-MM-dd'), OBS_MAX, 'UniformOutput', false);
Thank you all in advanced.
0 comentarios
Respuesta aceptada
Voss
el 3 de Nov. de 2022
load('OBS_MAX.mat')
OBS_MAX = cellfun(@set_dates_format,OBS_MAX,'UniformOutput',false);
function t = set_dates_format(t)
t.dates.Format = 'yyyy-MM-dd';
end
0 comentarios
Más respuestas (1)
Walter Roberson
el 3 de Nov. de 2022
You do not have a cell array of datetime objects: you have a cell array of tables, and you need to affect one particular variable inside the table. This is difficult to do without a helper function, but not difficult if you use a helper function.
d = cellfun(@bashdatesformat, OBS_MAX, 'uniform', 0)
function newT = bashdatesformat(T)
T.dates.Format = 'yyyy-MM-dd');
end
Without the helper function, it gets... messy... involving pulling apart tables and putting them back together into new tables. One might have hopes that you could at least do
cellfun(@(V) subsasgn(V, substruct('.', 'dates', '.', 'Format'), 'yyyy-MM-dd'), C, 'uniform', 0)
but that does not work in practice for this particular case. (It is a trick that can work for some other kinds of variables; see https://www.mathworks.com/matlabcentral/answers/440856-replacing-nans-with-zero-in-a-matrix-within-a-cell-array#answer_357449 )
0 comentarios
Ver también
Categorías
Más información sobre Dates and Time 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!