필터 지우기
필터 지우기

Convert duration from MM:SS to M:SS.

조회 수: 3 (최근 30일)
Gianluca Finotti
Gianluca Finotti 2018년 7월 12일
댓글: Gianluca Finotti 2018년 7월 13일
Hello everyone, I have a duration vector like this:
00:00
00:01
00:01
00:02
00:02
00:03
00:03
00:03
00:05
It only goes from 0 to 4 minutes so, in the plots I don't want to show something like: 01:05, but rather 1:05. That is, I want to get rid of the first digit and convert from mm:ss to m:ss. Is this possible?
Thank you for your time, Gianluca

답변 (1개)

Florian Floh
Florian Floh 2018년 7월 13일
Hello!
In order to achieve the desired time-format (or date format) you have to take a closer look at the function "datetime".
I tried the following code by myself and it should give the result you wish to achieve:
%Code
% Set up the vector (just for me to test) containing the time 'mm:ss'
a= ["01:00";
"01:01";
"01:01";
"01:02";
"01:02";
"01:03";
"01:03";
"01:03";
"01:05"];
% get the size of a
[rowsA colsA] = size(a);
% loop through the array in order to change the time-format
for i=1: rowsA
a(i)= datetime(a(i), 'InputFormat', 'mm:ss', 'Format', 'm:ss');
end
I hope this answer was helpful.
Kind regards, Florian
  댓글 수: 1
Gianluca Finotti
Gianluca Finotti 2018년 7월 13일
I forgot to mention that the class of the variable is "duration", so that code does not really work in this case. But I think I have found the solution: |
a.Format = 'm'
I still don't know whether I like it because in this case I get:
0 min
0.016667 min
0.016667 min
0.033333 min
0.033333 min
0.05 min
I think I'd rather have just the number without the "min". I don't know whether that is going to create problems with the plots. But we'll see.
Anyways, thank you very much for your answer.

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

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by