Automatically load latest .mat file
Show older comments
Hello,
My software is creating for every new measurement a new .mat file. I am wondering if there is a possibility to load the latest added mat file from a folder automatically?
4 Comments
Walter Roberson
on 12 Apr 2018
Is there anything that can be said about the name of the latest file? Are they always increasing in some numeric component of the file name? If they are then does that numeric component have leading zeros or not? e.g., does it go file8.dat file9.dat file10.dat or does it go file0008.dat file0009.dat file0010.dat ?
Can you be certain that the file that was modified most recently is the newest measurement? An example of where that might not be true is if your data analysis routine modifies the files, or if you might be moving files in or out in a different window file the sequence is running.
When a new file appears, is is always immediately ready for use? That would only happen in some cases where the file was very small (and even then would not be certain) -- or better if the protocol that created the files took special care to not make the file visible until it was ready to be used.
Sometimes protocols that make sure that files are not officially put in place until they are ready to be used tend up using temporary files in the same directory, in which case something that was just checking for the newest file would end up identifying the temporary file; such things can be avoided if you have a file pattern to match against.
Walter Roberson
on 12 Apr 2018
To confirm, the files are created by something else, and they are not moved into the folder until after they are complete?
This is not the same as something doing a save() into the directory, in which case there is a period between when the file starts to exist and the writing to the file finishes. (This can be a fair while for -v7.3 files.)
soepblik
on 12 Apr 2018
Answers (1)
Walter Roberson
on 12 Apr 2018
0 votes
Categories
Find more on File Operations 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!