How to automatically run all matlab files in a folder
Ältere Kommentare anzeigen
If there are many matlab edits in my folder, is there any command in matlab that can automatically read the edit in the folder and run it?
1 Kommentar
Image Analyst
am 13 Nov. 2022
What do you mean? Do you want to locate any m-files that have been edited since some previous time? And then run those m-files or find the lines in the file that are different from some earlier reference version of the file? You know that dir can give you the time date stamp of the files, right?
Antworten (1)
Karim
am 12 Nov. 2022
something like this should work
folder = 'YourFolder';
mfiles = dir(fullfile(folder, '*.m'));
% loop over the files
for k = 1:length(mfiles)
file = mfiles(k).name;
try
% try to run the current m file
run(fullfile(folder, file));
fprintf('succesful run: %s\n', file);
catch
% print message if it failed
fprintf('failed to run: %s\n', file);
end
end
4 Kommentare
peter huang
am 13 Nov. 2022
Karim
am 13 Nov. 2022
Indeed, if some (or even all) of the routines have a "clear all" then it won't work.
peter huang
am 14 Nov. 2022
Kategorien
Mehr zu Workspace Variables and MAT Files finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!