Running an m-file in each subfolders

5 ビュー (過去 30 日間)
Yaser Khojah
Yaser Khojah 2018 年 10 月 5 日
コメント済み: Yaser Khojah 2018 年 10 月 8 日
I'm looking for away to access subfoders and run script ('TESTING_4000.m') in each subfolder. Not sure what I'm missing in the code.
if true
% code
folder = 'C:\Deterministic\New Objectives_Log';
list = dir(fullfile(folder,'Log_4000*'));
nFile = {list([list.isdir]).name};
C = cell(1,numel(nFile));
for k = 1:numel(nFile)
C{k} = run(fullfile(folder,nFile{k},'TESTING_4000.m'));
end
end
Can anyone help please.
  5 件のコメント
Stephen23
Stephen23 2018 年 10 月 7 日
編集済み: Stephen23 2018 年 10 月 7 日
" Do you have another way you recommend?"
Yes: write functions rather than scripts, return the data that you need in output argument/s, save that data.
"after the first subfoder was run. The model stopped and showed k value in the for loop is undefined. Is there anyway, I can fix this?"
You did not show us any code, so we have no idea what your scripts are doing. Possibly you used clear in your code this causes existing variables to be cleared. Solution: do not use clear in any script or function. But until we actually see your code we can only guess, and debugging by guessing is very inefficient.
Yaser Khojah
Yaser Khojah 2018 年 10 月 8 日
Thanks Stephen for all the ideas and help. It is working finally.

サインインしてコメントする。

採用された回答

Yaser Khojah
Yaser Khojah 2018 年 10 月 5 日
I just updated the code and it is working now thanks.
run(fullfile(folder,nFile{k},'TESTING_4000.m'));

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAudio I/O and Waveform Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by