Reading a Specific Cell from Multiple Excel Spreadsheets
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Walter Roberson
il 3 Feb 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
0 Commenti
Vedere anche
Categorie
Scopri di più su Data Import from MATLAB in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!