How to remove rows in Table
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Manoj Krishnan Srinivasan
il 17 Mag 2021
Commentato: Manoj Krishnan Srinivasan
il 18 Mag 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 Commenti
Risposta accettata
Scott MacKenzie
il 17 Mag 2021
Modificato: Scott MacKenzie
il 17 Mag 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 Commenti
Scott MacKenzie
il 17 Mag 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Spreadsheets in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!