Time format conversion command
1 回表示 (過去 30 日間)
古いコメントを表示
This post is related to this thread:
If I want to convert
36:40.0
to
time in seconds, how do I do this?
2 件のコメント
Matt Fig
2012 年 10 月 16 日
What form is that? Is it a string and many in a character array or a cell array or what?
A = ['36:40.0';'36:41.0';'34:40.3']; % Like this?
A = {'36:40.0';'36:41.0';'34:40.3'}; % Like this?
採用された回答
Azzi Abdelmalek
2012 年 10 月 16 日
編集済み: Azzi Abdelmalek
2012 年 10 月 16 日
t={'36:40.0' ,'37:40.0' ;'39:40.0' ,'31:40.0'}
out=cellfun(@(x) sum(cellfun(@str2double, regexp(x,'[:.]','split')).*[3600 60 1]),t)
7 件のコメント
Azzi Abdelmalek
2012 年 10 月 18 日
編集済み: Azzi Abdelmalek
2012 年 10 月 18 日
Anthony, I suggest that you reformulate and repost your question, let it brief and very clear.
その他の回答 (1 件)
Matt Fig
2012 年 10 月 16 日
編集済み: Matt Fig
2012 年 10 月 16 日
If you have a cell array, I would do this:
A = {'36:40.0';'36:40.1';'34:40.3'}; % A cell array
B = '${num2str(str2num($1)*60+str2num($2))}';
B = regexprep(A,'(\d+):(\d+\.\d*)',B)
If you have a character array, then:
A = ['36:40.0';'36:41.0';'34:40.3']; % A character array.
B = '${num2str(str2num($1)*60+str2num($2))}';
B = char(regexprep(cellstr(A),'(\d+):(\d+\.\d*)',B))
3 件のコメント
Matt Fig
2012 年 10 月 16 日
編集済み: Matt Fig
2012 年 10 月 16 日
You seem to show where you converted to datenumbers using the DATENUM command. So why would it be surprising that you get datenumbers?
Show what this shows:
data{2}(1:3) % Or, what is in data{2}... strings?
If you don't see the strings in there, take the time to explore the data cell array before you run all these conversions on it. What is in data{1}? How about data{3}, etc...
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!