Date Conversion
이전 댓글 표시
Hi,
I have a <200x1 cell> array which consists of dates read through a text file. The dates are in the format yyyy/mm/dd hh:mm:ss:fff. I want to convert these dates into a matlab recognizable date vector which could then be later used in creating time series objects. I am not sure how to do this.
Thanks,
댓글 수: 2
Jan
2011년 12월 19일
Are you sure about the colon before the fractional seconds? Usually there is a dot.
Syed Abbas
2011년 12월 19일
채택된 답변
추가 답변 (3개)
Walter Roberson
2011년 12월 19일
datenum(YourArray, 'yyyy/mm/dd HH:MM:SS.FFF')
댓글 수: 4
Syed Abbas
2011년 12월 19일
Walter Roberson
2011년 12월 19일
What does size() and class() show for the first element of your cell array, YourCell{1} ?
Are the strings absolutely consistent?
What happens if you try
cellfun(@(S) datenum(S, 'yyyy/mm/dd HH:MM:SS.FFF'), YourCell)
At the moment, it seems to me that either you do not have a cell array of strings, or else that at least one of the entries is not in the expected format.
Syed Abbas
2011년 12월 19일
Syed Abbas
2011년 12월 19일
Jose Jeremias Caballero
2011년 12월 19일
Hello.
>> A={'2011/12/19 13:27:50.890';'2012/12/19 18:49:40.790'}
A =
'2011/12/19 13:27:50.890'
'2012/12/19 18:49:40.790'
>> vector=datevec(A, 'yyyy/mm/dd HH:MM:SS.FFF')
vector =
1.0e+003 *
2.0110 0.0120 0.0190 0.0130 0.0270 0.0509
2.0120 0.0120 0.0190 0.0180 0.0490 0.0408
Jan
2011년 12월 19일
A less intelligent, but much faster method than DATENUM:
dates = {'2011/11/11 11:11:11.111'; ...
'2012/12/12 12:12:12.121'};
function Vector = myDateConversion(DateCell)
S = sprintf('%s ', DateCell{:});
D = sscanf(S, '%d/%d/%d %d:%d:%f');
Vector = transpose(reshape(D, 6, []));
On Matlab 2009a this is 5 times faster than datevec(dates, 'yyyy/mm/dd HH:MM:SS.FFF'), but datevec is much smarter and converts the '2011/32/12' correctly.
The date topic has been discussed in Mike's blog recently:
카테고리
도움말 센터 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!