How to import a specific range using readtable
Afficher commentaires plus anciens
Hi,
I want to import some data from Excel sheets to Matlab using readtable. My problem is that the data is in the collums D, E and I (so not adjacent in Excel) and i only want the data from rows 37 until the end.
My code so far is:
cd 'C:\Users\julia\Desktop\Test\PCR\';
pathname = 'C:\Users\julia\Desktop\Test\PCR\';
fileList = dir('*.xls*');
numberOfFiles = length(fileList);
data = table
for i = 1:numberOfFiles
fileName = fileList(i).name;
table = readtable(fileName, 'Sheet', 'Results', 'Range', '?');
data = [data; table]; % not sure if this will work, the goal is to have a single table in the end with all the data
end
Your help is very much appreciated :)
2 commentaires
dpb
le 9 Sep 2019
Simplest will be to just read the whole spreadsheet and remove rows/columns not wanted.
The 'range' named parameter isn't flexible enough unless you know the full extent of the region desired in both columns and rows and it won't accept a non-contiguous range or multiple ranges at all.
The closest for your case would be to select the columns that include your wanted ones...
table=readtable(fileName, 'Sheet', 'Results', 'Range', 'D:I'); % read included columns
table=table(:,[1:2 6]); % purge unneeded cols
Julian
le 10 Sep 2019
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!