How do I incrementally increase an excel file everytime I run the code to avoid overwriting
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mohamed Sardheye
le 3 Oct 2022
Commenté : Mohamed Sardheye
le 10 Oct 2022
I create my excel sheet using writetable(T,'Test no21.xlsx') I would like to incrementally increase the number of the excel file to avoid overwriting the previous documents, how can I achieve that?
0 commentaires
Réponse acceptée
Geoff Hayes
le 3 Oct 2022
k = 22;
filename = sprintf('Test no%d.xlsx', k);
writetable(T, filename);
Or do you need to determine the 21 from the original file first?
3 commentaires
Geoff Hayes
le 7 Oct 2022
@Mohamed Sardheye - you could use regexpi to match on the integers in your filename. Perhaps something like
filename = 'Test no21.xlsx';
newFileNumber = str2double(filename(regexpi(filename, '[0-9]'))) + 1;
newFilename = sprintf('Test no%d.xlsx', newFileNumber);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!