I have a cell array, 11 x 1, and I need each cell converted. I've tried the datetime command but I only need HH:mm:ss.
>> t = {'0.0039583' '0.015058' '0.0091898' '0.012731' '0.00061343' '0.015799' '0.0022917' '0.036933' '0.018819' '0.0026042' '0.0019213'}
>> duration = datetime(t, 'ConvertFrom', 'datenum', 'Format', 'HH:mm:ss');
>> duration = datetime(t, 'ConvertFrom', 'datenum', 'Format', 'HH:mm:ss');
Error using datetime (line 614)
Unable to parse date/time text using the format 'HH:mm:ss'

댓글 수: 1

Juan, you accepted StarStrider's answer, but it's not clear you're doing the right thing.
First, you have what looks like numeric data read in as text. It seems like you should figure out if that is really what you want, or if you should be reading in data as numeric values.
But more to your question, I don't think you want datetimes at all, I think you want durations. ALL of your values are less than 1, suggestng that they are elapsed times or times-of-day. I think you want this:
>> t = {'0.0039583' '0.015058' '0.0091898' '0.012731' '0.00061343' '0.015799' '0.0022917' '0.036933' '0.018819' '0.0026042' '0.0019213'};
>> d = days(str2double(t));
>> d.Format = 'hh:mm:ss'
d =
1×11 duration array
Columns 1 through 10
00:05:41 00:21:41 00:13:13 00:18:19 00:00:53 00:22:45 00:03:18 00:53:11 00:27:05 00:03:45
Column 11
00:02:46
If you convert to datetimes, you will have values that are really things like
>> datetime(0.0039583,'convertFrom','datenum','Format','dd-MMM-yyyy G HH:mm:ss')
ans =
datetime
31-Dec-0002 BCE 00:05:41
which I doubt is what you want.

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

 채택된 답변

Star Strider
Star Strider 2018년 12월 3일

0 개 추천

Try this:
t = {'0.0039583' '0.015058' '0.0091898' '0.012731' '0.00061343' '0.015799' '0.0022917' '0.036933' '0.018819' '0.0026042' '0.0019213'}
dta = datetime(str2double(t), 'ConvertFrom', 'datenum', 'Format', 'HH:mm:ss');

댓글 수: 2

Juan Moreta
Juan Moreta 2018년 12월 4일
THANK YOU!
Star Strider
Star Strider 2018년 12월 4일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

질문:

2018년 12월 3일

댓글:

2018년 12월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by