Effacer les filtres
Effacer les filtres

How do I select files in a directory based upon day, month, and hour they were last modified or created?

11 vues (au cours des 30 derniers jours)
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

Réponses (1)

Walter Roberson
Walter Roberson le 9 Sep 2022
Modifié(e) : Walter Roberson le 9 Sep 2022
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
  2 commentaires
Benjamin Colbert
Benjamin Colbert le 9 Sep 2022
This doesn't run for me. Get two errors:
"Unable to resolve the name 'd.folder'."
I assume that's a typo so changed d.folder to f.folder.
Then i get:
Error in noise_scan_beforeafter (line 2)
filenames = fullfile({d.folder}, {d.name});

Connectez-vous pour commenter.

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!

Translated by