executing a function in multiple directories

4 ビュー (過去 30 日間)
Baba
Baba 2011 年 11 月 10 日
I have a function which i would like to execute in multiple directories. Because it takes a long time to finish executing in each directory I'd like to automate this to run overnight.
Please point me in the right direction.
  1 件のコメント
Sven
Sven 2011 年 11 月 10 日
Do you mean that you want yourfunction() to execute first on "c:/directory1", then "c:/directory2", then "c:/directory3", etc?
If so, I think you can write a short script that *calls* yourfunction() from different directories. For example:
cd 'c:/directory2'
yourfunction()
... etc.

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

採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 11 月 10 日
That is probably not the best word describing your need. Based on your previous questions, I guess you want to run a program. The program searches a folder for some file and then do processing on these files. You need to run the program searching multiple folders.
If you design your function in a way that the full path of the folder is an input argument, you could easily wrap this function in a for-loop to process lots of folders overnight. You could manually specify all the folders, or you can use dir() to get all the folders.
%%specify folder
Folder={'c:\MyFolder\F1';'c:\MyFolder\F2';'c:\MyFolder\F3'};
for k=1:length(Folder)
MyPlot(Folder{k});
end
%%or find the folder
ParentFolder='c:\MyFolder';
AllFile=dir(fullfile(ParentFolder,'F*'));
FolderOnly=AllFile([AllFile.isdir]);
for k=1:length(FolderOnly)
MyPlot(fullfile(ParentFolder,FolderOnly(k).name));
end
  1 件のコメント
Baba
Baba 2011 年 11 月 10 日
Thanks

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by