MATLAB: Import data from several .xlsx and different columns

excelimporting excel dataxlsx

Hi. I would like to import data from several .xlsx files. Currently, I have a reference .xlsx file that includes the locations of the target .xlsx files (in Column A) and two columns (D, F) that include the column reference for the data in the target .xlsx files I would like to import.
example:
  1. reference .xlsx file includes 1 column with file locations and 2 columns with column letters (AJ, F, etc.).[Reference .xlsx: Column A "C:\…\1.xlsx" and Column C "S" and Column D "AP"]
  2. matlab associates the file to the column letters (by row)
  3. import of date from column of the according .xlsx[Target .xlsx: Column S "123.42" and Column AP "213.32"]
I hope this is somehow understandable. Do you have any idea on how to do this? The script so far:
[~, ~, raw] = xlsread('C:\...\reference.xlsx','Worksheet1','A2:F22');
raw(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x),raw)) = {''};
cellVectors = raw(:,[1,2,3,4,6]);
raw = raw(:,5);
R = cellfun(@(x) ~isnumeric(x) && ~islogical(x),raw); % Find non-numeric cells
raw(R) = {NaN}; % Replace non-numeric cells
data = reshape([raw{:}],size(raw));
A = cellVectors(:,1);
B = cellVectors(:,2);
C = cellVectors(:,3);
D = cellVectors(:,4);
E = data(:,1);
F = cellVectors(:,5);
finalData = xlsread({'A', 'C'); % this part is the issue
clearvars data raw cellVectors R i;

Best Answer

Looks way too complicated -- something like
[~,txt]=xlsread('C:\...\reference.xlsx');
for i=1,size(txt,1)
C1C2=[txt(i,N1) ':' txt(i,N2)]; % build column references
data=xlsread(txt{i,1},C1C2); % read the range
... % do whatever with data here
end
should be about all that's needed. I assumed the file name is fully qualified and in first column to open the file and that the two column ranges are in columns N1 and N2, respectively. "Salt to suit..."