Azzera filtri
Azzera filtri

Extract the date from a standard filename

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

Risposta accettata

Jan
Jan il 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 Commento
James hall
James hall il 2 Apr 2013
Hi Jan,
This worked well after one correction
Str = 'Vehicle_XX62XXX_Type_130101';
index = strfind(Str, '_');
S = Str(index(end):end);
% StrDate = [S(5:6), '-', S(3:4), '-', S(1:2)];
StrDate = [S(6:7), '-', S(4:5), '-', S(2:3)];
I found that it was including a underscore into StrDate without.
I'm assuming you meant that the code was stupid, can fully accept that I may have been stupid using so many highpower functions to gain the same answer :D. Either way many thanks for the Help
James

Accedi per commentare.

Più risposte (0)

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