Import data from several .xlsx and different columns
Afficher commentaires plus anciens
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:
- 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"]
- matlab associates the file to the column letters (by row)
- 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;
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Spreadsheets dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!