How do I select files in a directory based upon day, month, and hour they were last modified or created?
7 次查看(过去 30 天)
显示 更早的评论
I have data that looks like this:
data = {"month", "day", "hour", "count"; 2, 5, 12, 25; 2, 6, 12 30; 2, 9 8, 16}
I want to read that data into matlab and then search a directory for files with a modifed date which matches the date and hour within a row, runs some analysis, and then move to the next row.Note, I have some rows which are same date and hour and others which skip multiple dates so i can't just run through the files in order. I dummied up the following code as a starting point but I am sure there's a better way to do this and it falls apart if there's more than a month of data.
data = readcsv("data.csv")
f = dir('*.wav")
for i = 1:length(data)
for n:length(f)
Day = str2num(F(2).date(:,1:2))
Hour = str2num(F(2).date(:,11:12))
if Day = data(i, 2) & Hour = data(i, 3)
audio = audio(f.name(n))
Do calcualtions
End
End
0 个评论
回答(1 个)
Walter Roberson
2022-9-9
编辑:Walter Roberson
2022-9-9
f = dir("*.wav");
filenames = fullfile({f.folder}, {f.name});
fdt = datetime([f.datenum], 'convertfrom', 'datenum');
[~, ~, day] = ymd(fdt);
[hour, ~, ~] = hms(fdt);
day = day(:); hour = hour(:);
numfiles = length(f);
data = readmatrix("data.csv");
for i = 1:size(data,1)
matchidx = find(data(i,2) == day & data(i,3) == hour) .'; %need row
for n = matchidx
audiodata = audio(filenames{n});
Do calculations
end
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!