Effacer les filtres
Effacer les filtres

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 vue (au cours des 30 derniers jours)
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'));

Réponse acceptée

OCDER
OCDER le 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

Plus de réponses (0)

Catégories

En savoir plus sur Search Path 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!

Translated by