Creating "sections" of file

2 visualizaciones (últimos 30 días)
jan mischke
jan mischke el 6 de Nov. de 2015
Comentada: Star Strider el 6 de Nov. de 2015
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

Respuesta aceptada

Star Strider
Star Strider el 6 de Nov. de 2015
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 comentarios
jan mischke
jan mischke el 6 de Nov. de 2015
Cool thank you, worked perfectly fine!!!
Star Strider
Star Strider el 6 de Nov. de 2015
My pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by