Filter löschen
Filter löschen

Hi i'm new to Matlab. i have directory : C:\D\Test and inside the ''Test'' i got sub folders A,B,C,D and E. i have a m.file called ''test.m'' in each sub folder. i wanna automate the run each test.m starting from A and then until E .

1 Ansicht (letzte 30 Tage)
here is the code I tried before, however it does not work.
dirinfo = dir('C:\D\Test');
dirinfo(~[dirinfo.isdir]) = [];%remove non-directories
subdirinfo = cell(length(dirinfo));
for i = 1 : length(dirinfo)
thisdir = dirinfo(i).name;
subdirinfo{i} = dir(fullfile(thisdir,'test.m'));
run(fullfile(thisdir,'test.m'));
end
here is the error message I get:
Error using run (line 73)
.\test.m not found.
Error in fish (line 7)
run(fullfile(thisdir,'test.m'));

Akzeptierte Antwort

OCDER
OCDER am 28 Sep. 2017
You also have to remove the '.' and the '..' directories that are returned by dir
dirinfo = dir('C:\D\Test');
dirinfo(~[dirinfo.isdir]) = []; %remove non-directories
dirinfo(endsWith({dirinfo.name}, '.')) = []; %removes the '.' and '..' directories

Weitere Antworten (0)

Kategorien

Mehr zu Search Path finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by