expression to calculate the time difference using Matlab functions
4 ビュー (過去 30 日間)
古いコメントを表示
採用された回答
Rik
2025 年 6 月 19 日
The closest to what you need is the duration function, but that has very limited support for text input.
str='3:19';
try,duration(str),catch ME,warning(ME.message),end
str='1:28.4';
try,duration(str),catch ME,warning(ME.message),end
You can also write something yourself:
delta=time2duration('3:19')-time2duration('1:28.4');
seconds(delta)
function d=time2duration(str)
RE=['((\d+):)?',... % optional hours
'(\d?\d):',... % one or two digit minutes
'(\d?\d(\.\d+)?)']; % seconds (with optional decimals)
x=regexp(str,RE,'tokens');
t = str2double([x{:}]);
t(isnan(t))=0;
d=duration(t(1),t(2),t(3));
end
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!