필터 지우기
필터 지우기

Creating "sections" of file

조회 수: 1 (최근 30일)
jan mischke
jan mischke 2015년 11월 6일
댓글: Star Strider 2015년 11월 6일
I have a file with 5 columns and a lot of rows. The values of the first three columns change every x rows. My goal is to split the file into sections:
0 0 0 x y
0 0 0 x y
0 1 5 x y
0 1 5 x y
0 2 9 x y
0 2 9 x y
.
.
.
So I want to read out the file and give all rows with 0 0 0 the section 1. So if i plot section 1 somehow, matlab will only consider these lines. Section 2 would be every line with 0 1 5 and again matalb will ignore every lines except for section 2 if I plot them. I could build some complicated loops around it, but I was told that matlab has some fancy ways to do something like that. As I said, my file is very big and I have tor ead it multiple times, so loops will slow down my script quite a lot probably. I can choose column 2 or 3 as a default value for the splitting, because these are the values that decide when to start a new section.
Thank you guys

채택된 답변

Star Strider
Star Strider 2015년 11월 6일
This seems to work, using the reshape and permute functions:
x = 10;
y = 20;
M = [0 0 0 x y
0 0 0 x y
0 1 5 x y
0 1 5 x y
0 2 9 x y
0 2 9 x y];
RowChange = 2; % Constant For ‘’Constant Rows
NewMatrix = reshape(M, RowChange, [], size(M,2));
Sections = permute(NewMatrix, [1 3 2]) % Page 3 Are The Sections
Sections(:,:,1) =
0 0 0 10 20
0 0 0 10 20
Sections(:,:,2) =
0 1 5 10 20
0 1 5 10 20
Sections(:,:,3) =
0 2 9 10 20
0 2 9 10 20
The ‘x’ for ‘every x rows’ is the ‘RowChange’ assignment, 2 here.
  댓글 수: 2
jan mischke
jan mischke 2015년 11월 6일
Cool thank you, worked perfectly fine!!!
Star Strider
Star Strider 2015년 11월 6일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by