Filter löschen
Filter löschen

Convert duration from MM:SS to M:SS.

3 Ansichten (letzte 30 Tage)
Gianluca Finotti
Gianluca Finotti am 12 Jul. 2018
Kommentiert: Gianluca Finotti am 13 Jul. 2018
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

Antworten (1)

Florian Floh
Florian Floh am 13 Jul. 2018
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 Kommentar
Gianluca Finotti
Gianluca Finotti am 13 Jul. 2018
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by