How do I read the last document from a directory

7 views (last 30 days)
I´ll explain my question:
I have a directory in which new results are posted as new documents everyday and Matlab does a process with the newest to give a results file. How can I set an .m file to choose the newest file everytime?

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 13 Mar 2013
Edited: Azzi Abdelmalek on 13 Mar 2013
d=dir('*.mat'); % if you need mat files
dates={d.date};
files={d.files};
[~,idx]=sort(datenum(dates));
new_file=files{idx(end)}

More Answers (1)

Bernardo
Bernardo on 26 Mar 2013
Thnx!!

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!