Can Matlab read the most recent made file in the default folder?
58 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, just want to know if Matlab can import the file that is most recent made based on their modified date and time?
I have several Excel files and want it read and do analysis?
Thanks.
0 commentaires
Réponse acceptée
Plus de réponses (2)
pfb
le 14 Avr 2015
Hi,
you could get the excel files with
d= dir('*xls');
and then compare the dates. These are in
d(j).date
You probably better convert them to numbers to compare them
dd = zeros(length(d));
for j = 1:length(d)
dd(j) =datenum(d(j).date);
end
[tmp i]=max(dd);
load(dd(i).name)
5 commentaires
Yan Kai Lai
le 26 Fév 2022
Modifié(e) : Yan Kai Lai
le 26 Fév 2022
I used the answer by pfb to read the most recent txt file. To make the answer more complete:
d = dir('somefolder/*txt');
dd = zeros(length(d), 1); % to init as vector instead of square matrix
for j = 1:length(d)
dd(j) = datenum(d(j).date);
end
[~, i] = max(dd); % tmp is the datenum, which is not necessary
lines = readlines(fullfile(d(i).folder, d(i).name)) % should be d instead of dd.
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!