Azzera filtri
Azzera filtri

Convert duration from MM:SS to M:SS.

3 visualizzazioni (ultimi 30 giorni)
Gianluca Finotti
Gianluca Finotti il 12 Lug 2018
Commentato: Gianluca Finotti il 13 Lug 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

Risposte (1)

Florian Floh
Florian Floh il 13 Lug 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 Commento
Gianluca Finotti
Gianluca Finotti il 13 Lug 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.

Accedi per commentare.

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by