is there a code to open and run all m files in a folder?
Ältere Kommentare anzeigen
Hi, I have multiple (about 50) different .m files in a folder. I wish to open and run each and every one of them using a matlab script. the output of this script would be a logical vector indicating which files had errors and which did not.
so is there a matlab code/ function that can open, run and check if there were run errors? thanks
Akzeptierte Antwort
Weitere Antworten (4)
Jakob Sørensen
am 22 Mär. 2014
1 Stimme
I don't know if there is a built-in function, but I think you could fairly easy make one yourself. Using the command dir you can acquire all the file names in a folder, then just loop through them, running them one-by-one.
Andy Campbell
am 24 Mär. 2014
Bearbeitet: Andy Campbell
am 24 Mär. 2014
To expand on per's answer, in R2014a you can do this using parameterized tests:
classdef TestAllFiles < matlab.unittest.TestCase
properties(TestParameter)
file = getListOfFiles;
end
methods(Test)
function testFileDoesNotError(testCase, file)
run(fullfile('C:\YourFolder', file));
end
end
end
function files = getListOfFiles
list = dir(fullfile('C:\YourFolder', '*.m'));
files = {list.name};
end
Then you can run them all and get your results:
result = runtests('TestAllFiles')
logicalVector = [result.Passed];
1 Kommentar
Itzik Ben Shabat
am 25 Mär. 2014
per isakson
am 22 Mär. 2014
Bearbeitet: per isakson
am 22 Mär. 2014
0 Stimmen
Yes, there is
This is much more than than you are asking for, however, it well worth to start applying Unit Testing. See http://software-carpentry.org/v4/test/ and http://stackoverflow.com/questions/67299/is-unit-testing-worth-the-effort
And see:
Image Analyst
am 22 Mär. 2014
0 Stimmen
Kategorien
Mehr zu Variables 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!