copy a string from filename and detect a new file in the folder
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I have a list of files like that :
data_acc_13042012.mat
data_acc_15042012.mat
data_acc_25042012.mat
data_acc_02052012.mat
the numbers correspond to date, for ex : 13/04/2012
Firstly,I would like to extract only the numbers in the filename and save them to a vector "date". Then I will display my data following this vector "date".
Secondly, for each time I run my code, I would like to detect if a new data file is added, for ex : data_acc_10052012.mat, etc. If yes, I redo the extraction of date and add it to the vector "date".
May anyone have an idea to do all these things please ?
Thanks for all your answers
Winn
1 Kommentar
Jan
am 4 Mai 2012
As usual it would be helpful if you show, what you have tried so far. I could imagine, that you have at least some lines of the code including the DIR command. If you post this, our suggestion could match your code.
Akzeptierte Antwort
Jan
am 4 Mai 2012
function ShowFiles(Folder)
persistent shownAlready
list = dir(fullfile(Folder, '*.mat'));
name = {list.name};
if ~isempty(shownAlready)
name_bak = name;
name = setdiff(name, shownAlready);
shownAlready = name_bak;
end
blockStr = sprintf('%s;', name{:});
number = sscanf(blockStr, 'data_acc_%2d%2d%4d.mat;');
dateV = transpose(reshape(number, 3, []));
dateD = datenum(dateV(:, 3), dateV(:, 2), dateV(:, 1));
[dum, order] = sort(dateD);
for i = order
<do something with the file: fullfile(Folder, name{i})>
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!