필터 지우기
필터 지우기

How to select odd and even rows from a text file

조회 수: 3 (최근 30일)
Cody
Cody 2011년 7월 6일
Hi
I have a text file with a big matrix. I want to select all the even rows and export to a new text file, and then select all the odd rows to another new text file.
For example, I have a A.txt with a matrix like below
1 1 1 …
2 2 2…
3 3 3 …
4 4 4 …
I want to separate them into to two new text files, as shown below
B.txt
1 1 1 …
3 3 3 …
C.txt
2 2 2 …
4 4 4 …
Thank you so much.

채택된 답변

Sean de Wolski
Sean de Wolski 2011년 7월 6일
X = X(1:2:end,:); %keep odd rows
X = X(2:2:end,:); %keep even rows

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by