Extracting characters out of a string array

Hi guys,
So I have a n rows by 1 column cell array with each cell containing a date string eg.20/02/201205:45:00PM. I would like to plot some data using this date and time string as the x-axis but notice that those entries are not in a format which matlab recognizes (no space between the date and the time).
So I would want to extract the date section and time section out of those entries and reconstruct my string array, putting a space in between so I can use the datenum function. What would be a good way to do this? Thanks in advance!!

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 2월 20일

0 개 추천

c = {'20/02/201205:45:00PM';'21/02/201205:45:00AM'}
out = datenum(c,'dd/mm/yyyyHH:MM:SSPM')
out2 = datestr(out,'dd/mm/yyyy HH:MM:SS PM')

댓글 수: 1

Vincent
Vincent 2012년 2월 20일
Thz a lot andrei!! Never realised that I can specific the date string format in the datenum function!!

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

추가 답변 (0개)

카테고리

도움말 센터File 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