Borrar filtros
Borrar filtros

Getting just the time in Date-time cell

3 visualizaciones (últimos 30 días)
Yannick Tabot Njami
Yannick Tabot Njami el 28 de Oct. de 2022
Respondida: Steven Lord el 28 de Oct. de 2022
Hello Please can someone help me get just the time in this date-time cell array?
I will appreciate the efforts.
attached is the data.
the first 10 rows looks like this and i want a new row with just the time such [12:33:00 12:34:00 12:35:00] and so on
'16.09.2020 12:33:00'
'16.09.2020 12:34:00'
'16.09.2020 12:35:00'
'16.09.2020 12:36:00'
'16.09.2020 12:37:00'
'16.09.2020 12:38:00'
'16.09.2020 12:39:00'
'16.09.2020 12:40:00'
'16.09.2020 12:41:00'
'16.09.2020 12:42:00'
thanks

Respuesta aceptada

Florian Bidaud
Florian Bidaud el 28 de Oct. de 2022
Hi
for i = 1:length(txt(:,1))
if ~isempty()
txtSplit = strsplit(txt{i,1},' ');
txt{i,2} = txtSplit{2};
end
The value when the time is 00:00 is empty, so you will have to add the following check :
for i = 1:length(txt(:,1))
txtSplit = strsplit(txt{i,1},' ');
if length(txtSplit) == 1
txt{i,2} = '00:00:00';
else
txt{i,2} = txtSplit{2};
end
end

Más respuestas (1)

Steven Lord
Steven Lord el 28 de Oct. de 2022
I would turn the text representation of the dates and times into a datetime array then call the timeofday function on that array. If you need the representations as a string you can call string on the duration array created by timeofday.
s1 = {'16.09.2020 12:33:00'
'16.09.2020 12:34:00'
'16.09.2020 12:35:00'
'16.09.2020 12:36:00'
'16.09.2020 12:37:00'
'16.09.2020 12:38:00'
'16.09.2020 12:39:00'
'16.09.2020 12:40:00'
'16.09.2020 12:41:00'
'16.09.2020 12:42:00'};
dt = datetime(s1)
dt = 10×1 datetime array
16-Sep-2020 12:33:00 16-Sep-2020 12:34:00 16-Sep-2020 12:35:00 16-Sep-2020 12:36:00 16-Sep-2020 12:37:00 16-Sep-2020 12:38:00 16-Sep-2020 12:39:00 16-Sep-2020 12:40:00 16-Sep-2020 12:41:00 16-Sep-2020 12:42:00
du = timeofday(dt)
du = 10×1 duration array
12:33:00 12:34:00 12:35:00 12:36:00 12:37:00 12:38:00 12:39:00 12:40:00 12:41:00 12:42:00
s2 = string(du)
s2 = 10×1 string array
"12:33:00" "12:34:00" "12:35:00" "12:36:00" "12:37:00" "12:38:00" "12:39:00" "12:40:00" "12:41:00" "12:42:00"

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by