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 次查看(过去 30 天)
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'));

采纳的回答

OCDER
OCDER 2017-9-28
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Search Path 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by