Creating "sections" of file

2 ビュー (過去 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 Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by