Use date strings to specify date range of matfiles to process

1 view (last 30 days)
Hi Guys
I have the following file structure
VehicleName\Matfiles\Month\VehicleName_Registration_Type_yymmdd.mat
Currently I can only process data from a vehicles month folder.
I want to compare data for the same vehicle but in a specified date range
e.g
130101-130210
this would take me across two month folders and also only use data until the 10th of Feb.
My Current Code is
VehicleInfo=find(ismember(FTDatabase(:,1),VehicleName));
if isempty(VehicleInfo)
error([VehicleName, ' is not in vehicle database'])
end
Database1 = Database{VehicleInfo, 2};
Database2 = Database{VehicleInfo, 3};
Database3 = Database{VehicleInfo, 4};
Database4 = Database{VehicleInfo, 5};
end
MATfileDIR = ([ DataLocation,'\',Program,'\',Application,'\' VehicleName,'\MatData_Files','\',Month,'_matfiles']);
MatFiles = what(MATfileDIR);
DayFiles=MatFiles.mat;
i=0;
for WhichMat = 1:length(DayFiles);
SelectedMat = DayFiles{WhichMat};
StructureName = DayFiles;
MATfile = ([MATfileDIR, '\', SelectedMat]);
index = strfind(SelectedMat,'_');
S = SelectedMat(index(end):end); % Supplied By Jan Simon
DateVal= {[S(6:7),S(4:5),S(2:3)];};% Supplied by Jan Simon
DateNum = datenum(DateVal,'ddmmyy');
Date = DateNum;
i =i+1;
DATA = load(MATfile);
disp({'Loading' , SelectedMat})
Database holds the vital information for each vehicle. So the end result that I cant get to work is MATfile being a list of the filepath of all the matfiles that have the correct date range
  3 Comments
James hall
James hall on 5 Apr 2013
Each Mat file contains ~200 matrices of numerical data realting to how a vehicle runs. I want to load these mat files to create daily averages and maximums and histograms.
I have written an update to script above that now lists all the matfiles for the vehicle being requested.
% MATfileDIR = ({[ DataLocation,'\',Program,'\',Application,'\' VehicleName,'\MatData_Files']);
[Sy Sm] =datevec(daterangestart)
[Fy Fm] =datevec(daterangeend)
monthsplot = 1+ (Fm-Sm)
VehilclefileDIR = ([ DataLocation,'\',Program,'\',Application,'\' VehicleName,'\MatData_Files']);
Months = dir(VehilclefileDIR)
Months (~[Months.isdir])
tf = ~ismember({Months.name},{'.','..'})
Folders = Months(tf)
NumberOfFolders = length(Folders)
Months = ({Folders.name})
Months = Months.'
i=1
for Dayfolders = 1:length(Months);
if i < 2
MATfileDIR = ([ DataLocation,'\',Program,'\',Application,'\' VehicleName,'\MatData_Files','\',Months(i)]);
MATfileDIR = cell2mat(MATfileDIR)
MatFiles = what(MATfileDIR);
DayFiles=MatFiles.mat;
end
if i > 1
MATfileDIR = ([ DataLocation,'\',Program,'\',Application,'\' VehicleName,'\MatData_Files','\',Months(i)]);
MATfileDIR = cell2mat(MATfileDIR)
MatFiless = what(MATfileDIR);
DayFiless = MatFiless.mat
DayFiles = [DayFiles;DayFiless]
end
i=i+1
end
i=1
for WhichMat = 1:length(DayFiles)
SelectedMat = DayFiles{WhichMat}
StructureName = DayFiles
MATfile = ([MATfileDIR, '\', SelectedMat])
index = strfind(SelectedMat,'_')
S = SelectedMat(index(end):end)
DateVal= {[S(6:7),S(4:5),S(2:3)];}
DateNum = datenum(DateVal,'ddmmyy')
% Date = datestr(DateNum,'dd-mm-yy');
end
end
I am acutly aware however that this is a very inefficient way to do this hence needing the help :)
Jan
Jan on 5 Apr 2013
Edited: Jan on 5 Apr 2013
I still do not understand what you are asking for. Do you want only files, whose creation (or modification?) date is in a certain interval? I do not think, that the large posted code helps to understand, what you want.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!