Convert each cell using datetime
古いコメントを表示
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 件のコメント
Peter Perkins
2018 年 12 月 11 日
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.
採用された回答
その他の回答 (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!