필터 지우기
필터 지우기

Routine that recall various files and apply a script

조회 수: 4 (최근 30일)
Guglielmo Giambartolomei
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.

채택된 답변

Walter Roberson
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
Guglielmo Giambartolomei
Guglielmo Giambartolomei 2016년 11월 23일
Thank you Walter Roberson, but I'm too a beginner to understand your code. I appreciate anyway; thank you very much!
Walter Roberson
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
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
  댓글 수: 1
Guglielmo Giambartolomei
Guglielmo Giambartolomei 2016년 11월 22일
You're right Jan, and I thank you but it's not clear what the code in your link do.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by