Tricky correction of faulty time list
Mostrar comentarios más antiguos
Hi. I have a Nx1 cell array containing different time values as strings, mixed wildly. It looks something like this:
12:00
12:05
13:45
09:15
08:25
*08:32*
15:20
*15:26*
but a lot longer... As you can see, the minute values are almost all multiples of 00:05. But some random ones are shifted by one or two minutes.
Is there a way I can run through the array and correct the shifted values? So in my example I would want to change '15:26' to '15:25' and '08:32' to '08:30'.
If it is not possible to automate it, finding them would be also be okay - so that I could display their respective row numbers in a message box to be able to correct them manually.
Thanks in advance for any help!
Respuesta aceptada
Más respuestas (1)
v = {'12:00';'12:05';'13:45';'09:15';'08:25';'08:32';'15:20';'15:26'};
for k = 1:numel(v)
w = v{k};
if w(5) < '5'
w(5) = '0';
else
w(5) = '5';
end
v{k} = w;
end
[EDITED] Less readable:
for k = 1:numel(v)
w = v{k};
w(5) = '0' + 5 * (w(5) >= '5'); % Implicit conversion to CHAR
v{k} = w;
end
2 comentarios
Marc Jakobi
el 23 de Sept. de 2013
Jan
el 23 de Sept. de 2013
I've suggested this method for another reason that the run time: It is simple and easy to debug. If a reader needs 5 seconds less to understand it, it does not matter, if it runs in 0.005 or 0.002 seconds.
Categorías
Más información sobre Cell Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!