How do I separate date and time of a raw date?

조회 수: 1 (최근 30일)
aishah
aishah 2018년 3월 30일
댓글: Walter Roberson 2019년 2월 24일
>> a = untitled.startDate(1:10)
a =
10×1 categorical array
2013-07-10 00:01:00.0
2013-07-17 00:01:00.0
2013-06-29 00:01:00.0
2013-07-17 00:01:00.0
2013-05-11 00:01:00.0
2013-05-31 00:01:00.0
2013-06-06 00:01:00.0
2013-08-31 00:01:00.0
2013-05-21 00:01:00.0
2013-08-06 00:01:00.0
>> a.Format = 'dd-MMM-yyyy'
Error using categorical/subsasgn (line 87)
Attempt to assign field of non-structure array.
  댓글 수: 3
aishah
aishah 2018년 3월 30일
What I did was, I imported the data into a 'table'. And I convert the data to 'Categorical Array'.
aishah
aishah 2018년 3월 30일
The imported data type is 'datetime'.

댓글을 달려면 로그인하십시오.

채택된 답변

Ahmet Cecen
Ahmet Cecen 2018년 3월 30일
편집: Ahmet Cecen 2018년 3월 30일
arrayfun(@(x) strsplit(x,' '),string(a),'UniformOutput',false)
string(a) - this makes the data easily process-able, converts to a string array.
@(x) strsplit(x,' ') - this is a function that splits each string into parts whenever a space(' ') is located(which works for your case)
arrayfun - applies the above function to each "row" in the string array.
  댓글 수: 7
aishah
aishah 2018년 3월 30일
b = reshape([k{:}],2,length(a))'
Undefined variable "k" or class "k".
aishah
aishah 2018년 3월 30일
celldisp(b)
b{1} =
"2013-07-10" "00:01:00.0"
b{2} =
"2013-07-17" "00:01:00.0"
b{3} =
"2013-06-29" "00:01:00.0"
b{4} =
"2013-07-17" "00:01:00.0"
b{5} =
"2013-05-11" "00:01:00.0"
b{6} =
"2013-05-31" "00:01:00.0"
b{7} =
"2013-06-06" "00:01:00.0"
b{8} =
"2013-08-31" "00:01:00.0"
b{9} =
"2013-05-21" "00:01:00.0"
b{10} =
"2013-08-06" "00:01:00.0"

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Peter Perkins
Peter Perkins 2018년 4월 2일
Don't do any of that.
You've read the timestamps in as datetimes. Don't fight that. Assuming you have a table T:
T.StartTime = timeofday(T.StartDate);
T.StartDate = dateshift(T.StartDate,'start','day);
  댓글 수: 6
Steph
Steph 2019년 2월 24일
I missteated my problem I think, I am doing regressions on the data that is collected on each of the specific days. Not on the dates or days themselves
Walter Roberson
Walter Roberson 2019년 2월 24일
Then you do not need to convert the dates + times or datetime objects to numeric. What you need to do is be able to group your data based upon date. You should have a look at splitapply() -- or convert the table to a timetable() object and use retime()

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by