Routine that recall various files and apply a script
4 ビュー (過去 30 日間)
古いコメントを表示
Guglielmo Giambartolomei
2016 年 11 月 21 日
コメント済み: Walter Roberson
2016 年 11 月 23 日
Hello everyone, I have a question. I wrote a simple script that analyse a xlsx file. I have many of these files in a single directory. Can someone recommend me a skeleton of a routine that automatically recall these files and apply the script at each file? Thank you very much.
0 件のコメント
採用された回答
Walter Roberson
2016 年 11 月 22 日
projectdir = 'C:\Directory\Where\The\FilesAre';
dinfo = dir( fullfile( projectdir, '*.xlsx') );
filenames = fullfile( projectdir, {dinfo.name} );
for K = 1 : length(filenames)
thisfile = filenames{K};
[num, txt, raw] = xlsread(thisfile);
...
end
2 件のコメント
Walter Roberson
2016 年 11 月 23 日
projectdir = 'C:\Directory\Where\The\FilesAre';
cd(projectdir);
dinfo = dir( '*.xlsx' );
for K = 1 : length(dinfo)
thisfile = dinfo(K).name;
[num, txt, raw] = xlsread(thisfile);
...
end
dir() returns a structure array of information about the files it finds. You need to index that structure at an offset to find information for one file. One of the fields that is recorded for every file is "name", the name of the file. Pull that out of the structure and read the information from the file.
その他の回答 (1 件)
Jan
2016 年 11 月 21 日
This sounds like a frequently asked question. Then a search in the net should be successful. Et voila: FAQ: How can I process a sequence of files
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!