필터 지우기
필터 지우기

Getting just the time in Date-time cell

조회 수: 3 (최근 30일)
Yannick Tabot Njami
Yannick Tabot Njami 2022년 10월 28일
답변: Steven Lord 2022년 10월 28일
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

채택된 답변

Florian Bidaud
Florian Bidaud 2022년 10월 28일
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

추가 답변 (1개)

Steven Lord
Steven Lord 2022년 10월 28일
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"

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by