How to remove rows in Table
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Manoj Krishnan Srinivasan
el 17 de Mayo de 2021
Comentada: Manoj Krishnan Srinivasan
el 18 de Mayo de 2021
I have an excel file with 20000+ rows & 10 columns. I need only data of few rows (ex. 650 to 1200, 3000 to 3600) present in the table along with its related columns and the remaining rows must be deleted. Please help me with a simple code for this task.
0 comentarios
Respuesta aceptada
Scott MacKenzie
el 17 de Mayo de 2021
Editada: Scott MacKenzie
el 17 de Mayo de 2021
You want to read 10 columns of data in rows 650 to 1200. There is no need to read the entire file. Try this...
inFile = 'yourfile.xlsx';
dataRange = 'A650:J1200';
worksheet = 1;
T = readtable(inFile, 'FileType', 'spreadsheet', 'Sheet', worksheet, 'Range', dataRange);
3 comentarios
Scott MacKenzie
el 17 de Mayo de 2021
There are many ways to read and manipulate data. You could read the two sections of data separately, then concatenate the two matrices:
T1 = readtable(inFile, 'FileType', 'spreadsheet', 'Sheet', worksheet, 'Range', 'A650:J1200');
T2 = readtable(inFile, 'FileType', 'spreadsheet', 'Sheet', worksheet, 'Range', 'A3000:J3600');
T = [T1; T2];
Or, you could read all the data, then reassign T to itself while specifying only the rows of interest:
T = readtable(inFile, 'FileType', 'spreadsheet', 'Sheet', worksheet);
T = T([650:1200 3000:3600],:);
For exporting data to a .csv file, use writetable, for example...
writetable(T, 'newfile.csv');
For all the details and examples, I suggest you study the documentation for readtable and writetable. Good luck.
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!