How to remove rows in Table

1 回表示 (過去 30 日間)
Manoj Krishnan Srinivasan
Manoj Krishnan Srinivasan 2021 年 5 月 17 日
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.

採用された回答

Scott MacKenzie
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
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.
Manoj Krishnan Srinivasan
Manoj Krishnan Srinivasan 2021 年 5 月 18 日
Thank you Scott.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by