Automatically load latest .mat file

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 comentarios

Walter Roberson
Walter Roberson el 12 de Abr. de 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.
soepblik
soepblik el 12 de Abr. de 2018
Editada: soepblik el 12 de Abr. de 2018
thanks for your quick reply! I was thinking of giving the .mat files a name with date and time, but file1 file2 is also oke. The files can be implemented immediately, no changes needed afterwards. Also the most recent file is also the newest measurement, because the file is put in the folder after the measurement is finished. So no temporary files inside the folder
Walter Roberson
Walter Roberson el 12 de Abr. de 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
soepblik el 12 de Abr. de 2018
Sorry I maybe explained it not well. But indeed the file is only moved to the folder after it is fully completed

Iniciar sesión para comentar.

Categorías

Más información sobre File Operations en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 12 de Abr. de 2018

Respondida:

el 12 de Abr. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by