datestr, add non-interpreted characters into format

5 visualizaciones (últimos 30 días)
Vincent
Vincent el 30 de Sept. de 2011
Hi, I have two cell-arrays containing values like
7.345 * 10^5
7.344 * 10^5
2011-01-04_16h50m20s
2010-11-30_07h00m02s
I want to concatenate both and sort the Cell-Array by time (found a function "sortcell" in File Exchange). But the Array first has to be of the same format, of course.
How can i achieve this? I thought of converting the datenum-integers to date-strings but I didn't get how to write "h" or something in my string, especially with cellstrings.
Thank you in advance.

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 30 de Sept. de 2011
data = {'2011-01-04_16h50m20s'
'2010-11-30_07h00m02s'}
date2 = cellfun(@(x)[x{:}],regexp(data,'[-_hms]','split'),'un',0);
[ign,ind] = sort(datenum(date2,'yyyymmddHHMMSS'));
out = data(ind)
EDIT
[ign,ind] = sort(datenum(regexprep(data,'[-_hms]',''),'yyyymmddHHMMSS'));
out = data(ind)

Más respuestas (1)

Vincent
Vincent el 30 de Sept. de 2011
Okay, seems like a cellfun or loop is neccessary. But I must admit: your solution is very tolerant against errors.
Didn't know yet that it is possible to abbreviate 'UniformOutput' by 'un'. Nice :)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by