How to import a specific range using readtable
Mostrar comentarios más antiguos
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 comentarios
dpb
el 9 de Sept. de 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
el 10 de Sept. de 2019
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Spreadsheets en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!