Azzera filtri
Azzera filtri

Creating "sections" of file

1 visualizzazione (ultimi 30 giorni)
jan mischke
jan mischke il 6 Nov 2015
Commentato: Star Strider il 6 Nov 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

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by