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

回答(1 个)

Walter Roberson
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

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by