datestr, add non-interpreted characters into format

5 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 30 Set 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)

Più risposte (1)

Vincent
Vincent il 30 Set 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 :)

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by