Reading a Specific Cell from Multiple Excel Spreadsheets

9 visualizaciones (últimos 30 días)
Zachary Bryant
Zachary Bryant el 3 de Feb. de 2019
Respondida: Walter Roberson el 3 de Feb. de 2019
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

Respuestas (1)

Walter Roberson
Walter Roberson el 3 de Feb. de 2019
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

Categorías

Más información sobre Data Import from MATLAB en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by