Extract the date from a standard filename
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi Guys,
I have thousands of .MAT files which hold data with the file name convention
Vehicle_Registration_Type_Date.MAT
the Type is exactly the same for every file.
Currently I am using
DateLocation=regexp(SelectedMat,'\d');
DateVals=regexp(SelectedMat,'\d','match');
DateVal = cell2mat(DateVals);
DateNum = datenum(DateVal,'yymmdd');
DateStr = datestr(DateNum, 'dd-mm-yy');
I am finding that the 2 digits in the Registration are appearing in the datestring making it wrong.
e.g Vehicle_XX62XXX_Type_130101 returns 62130101
The date is in US format yymmdd although I am in the UK
is there a way to filter the string to only be searched after type?
Any help would be greatly appreciated
Many Thanks
James
0 Kommentare
Akzeptierte Antwort
Jan
am 2 Apr. 2013
Str = 'Vehicle_XX62XXX_Type_130101';
index = strfind(Str, '_');
S = Str(index(end):end);
StrDate = [S(5:6), '-', S(3:4), '-', S(1:2)];
This is a really stupid approach, without 2 REGEXPs, CELL2MAT, DATENUM and DATESTR, which are all such powerful, that they need a lot of time.
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!