How can I convert a cell array of times:
C = {'12:35' '11:35'
'14:21' '11:01'}
to an array of doubles
B = 12:35 11:35
14:21 11:01
where I can do mathematical operations with it if given a certain amount of minutes.
For example, 12:35 + 60 minutes = 13:35.

 採用された回答

Stephen23
Stephen23 2015 年 10 月 14 日
編集済み: Stephen23 2015 年 10 月 14 日

0 投票

The output that you request is not possible, because the colon character : cannot be part of a double array. If you really want those numbers in a numeric array then that array will need to be a different size to the input cell array. Here is one easy conversion that puts the hours on the top row and the minutes underneath:
>> C = {'12:35','11:35';'14:21','11:01'};
>> M = sscanf(char(C)','%2d:%2d',[2,numel(C)])
M =
12 14 11 11
35 21 35 1
Of course if you really want those values in exactly the same shape array as the input cell array C, then the minutes can be converted to decimal fractions of the hours:
>> N = reshape(M(1,:)+M(2,:)/60,size(C))
N =
12.583 11.583
14.350 11.017

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2015 年 10 月 14 日

0 投票

You will need to use datetime objects or duration objects, which were introduced in R2014b.
Jan
Jan 2015 年 10 月 14 日

0 投票

C = {'12:35' '11:35'
'14:21' '11:01'}
D = datenum(C, 'HH:MM')

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

タグ

質問済み:

2015 年 10 月 14 日

編集済み:

2015 年 10 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by