How to remove rows in Table
5 次查看(过去 30 天)
显示 更早的评论
Manoj Krishnan Srinivasan
2021-5-17
评论: Manoj Krishnan Srinivasan
2021-5-18
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 个评论
采纳的回答
Scott MacKenzie
2021-5-17
编辑:Scott MacKenzie
2021-5-17
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 个评论
Scott MacKenzie
2021-5-17
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!