Reading a Specific Cell from Multiple Excel Spreadsheets

10 ビュー (過去 30 日間)
Zachary Bryant
Zachary Bryant 2019 年 2 月 3 日
回答済み: Walter Roberson 2019 年 2 月 3 日
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 Center および File ExchangeData Import from MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by