Extract the date from a standard filename
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Jan
le 2 Avr 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Dates and Time dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!