- https://de.mathworks.com/matlabcentral/fileexchange/10959-sort-nat--natural-order-sort
- https://www.mathworks.com/matlabcentral/fileexchange/34464-customizable-natural-order-sort
I want to save a mat. file each time the program runs with a different name.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
arvind ramasamy
el 28 de Nov. de 2017
Comentada: Walter Roberson
el 28 de Nov. de 2017
for example, when I run program for the first time i want to save it as ' text1.mat' second time 'text2.mat' etc...
0 comentarios
Respuesta aceptada
Jan
el 28 de Nov. de 2017
Editada: Jan
el 28 de Nov. de 2017
Folder = tempdir; % Define accordingly
FileList = dir(fullfile(Folder, 'text*.mat'));
NewFile = fullfile(Folder, sprintf('text%d.mat', numel(FileList) + 1));
This fails, if you delete some of the files afterwards. Then this helps:
NameList = natsort({FileList.name});
LastIndex = sscanf(NameList{end}, 'text%d.mat'));
NewFile = fullfile(Folder, sprintf('text%d.mat', LastIndex + 1));
Or prefer:
nowStr = datestr(now, 'yyyy-mm-dd_HHMMSS');
NewFile = fullfile(Folder, ['text', nowStr, '.mat']);
But remember that this fails, if you create more than 1 file per second or during the change of the daylight-saving-time.
2 comentarios
Walter Roberson
el 28 de Nov. de 2017
NameList = natsort({FileList.name});
LastIndex = sscanf(NameList{end}, 'test_%damp.mat'));
NewFile = fullfile(Folder, sprintf('test_%damp.mat', LastIndex + 1));
Más respuestas (0)
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!