How to remove a pattern of rows from .csv

So I have a .csv file with 134,433 rows. I want to delete a pattern of rows: 1 through 125, and 256 through 1149. This pattern repeats, so I would then delete 1150 through 1275, and 1406 through 2299. How would I write a simple code that deletes these certain rows?

2 件のコメント

Akira Agata
Akira Agata 2017 年 7 月 12 日
What is a rule of your delete pattern? Rows 1 through 125 contains 125 lines. But rows 1150 through 1275 contains 126 lines.
Andrew L
Andrew L 2017 年 7 月 12 日
That was a typo, I meant to write 1274, so the pattern does indeed repeat

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

 採用された回答

Akira Agata
Akira Agata 2017 年 7 月 12 日

0 投票

I believe the following code can help.
% Read CSV file
filename = 'yourFile.csv';
data = csvread(filename); % 134,433 rows
% Make a delete pattern
num = 2299*ceil(134433/2299);
idx = false(num,1);
for kk = 1:ceil(134433/2299)
idx([1:125, 256:1149, 1150:1275, 1406:2299]+(2299*(kk-1))) = true;
end
idx = idx(1:134433);
% Delete selected rows
data(idx,:) = [];

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeVariables についてさらに検索

質問済み:

2017 年 7 月 11 日

コメント済み:

2017 年 7 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by