Reading a Specific Cell from Multiple Excel Spreadsheets
조회 수: 10 (최근 30일)
이전 댓글 표시
I am trying to read a specific cell from multiple excel spreadsheets that are saved under an incrementing name (for example plot1.xlsx, plot2.xlsx, plot3.xlsx, ...., plotn.xlsx). I'm attempting to use xlsread inside of a while loop to read the specific cell from each spreadsheet and store it in a different cell of an array. Is there a way that this can be done? I've looked a bit into 4D arrays but I'm not sure that would solve the problem. Here's my code so far:
prompt = 'What is the location of the files? Ex: C:\\Users\\.... ';
location = input(prompt,'s');
dir(location);
prompt3 = 'What is the general file name without the number?: ';
filename = input(prompt3,'s');
prompt2 = 'What is the last file number?: ';
last=input(prompt2);
i=1;
ar = zeros(60,1);
while i<=last
i = num2str(i);
filename1 = [filename,i];
i = str2num(i);
ar(i:1) = xlsread(filename1, 'B2:B2');
i = i+1;
end
댓글 수: 0
답변 (1개)
Walter Roberson
2019년 2월 3일
prompt = 'What is the location of the files? Ex: C:\\Users\\.... ';
location = input(prompt,'s');
prompt3 = 'What is the general file name without the number?: ';
filename = input(prompt3,'s');
prompt2 = 'What is the last file number?: ';
last=input(prompt2);
ar = zeros(last,1);
for i = 1 : last
filename1 = fullfile(location, sprintf('%s%d.csv', filename, i))
ar(i) = xlsread(filename1, 'B2:B2');
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!