0

I have a text file that has consequtive integer values around strings. This file looks like that:

This is the set for x = 100
---------------------------

For y=COLUMN 1 we have
1232
3ff3
4a45
23d4
5323
...
...
END of COLUMN 1 meas

For y=COLUMN 2 we have
1232
3c43
4545
2d24
5a23
...
...
END of COLUMN 2 meas

This is the set for x = 200
---------------------------

For y=COLUMN 1 we have
2b23
1232
d387
6f74
4c47
...
...
END of COLUMN 1 meas

For y=COLUMN 2 we have
354d
a546
3c63
5a46
a349
...
...
END of COLUMN 2 meas

This is the set for x = 530
---------------------------
..........
..........

What I would like to do is to strore the values in between the strings into seperate arrays. That is, from 'For y=COLUMN 1 we have' to 'END of COLUMN 1 meas' will be strored in to ArrayA, from 'For y=COLUMN 2 we have' to 'END of COLUMN 2 meas' into ArrayB, etc.

After that, I need to find all the values fo 'x' and store them into a string array named ArrayX. That is, this should be look like that:

ArrayX =

'x=100'    'x=200'    'x=501'

If anyone can help, I will really appreciate it.

Amro
  • 123,847
  • 25
  • 243
  • 454
limp
  • 889
  • 2
  • 14
  • 22
  • Approximately how large is the total input file? If it will all fit into memory, then you may have some additional, relatively easy options using a series of regular expressions on the full character set. – Pursuit Nov 19 '11 at 01:39
  • What exactly is your problem? You can read lines of a file using `fgetl` and extract information from them using regular expressions (see the `regexp` command). – Florian Brucker Aug 28 '12 at 13:56

1 Answers1

0

I'm not sure you still need this information, but I have the same problem and find this solution for this;

formatSpec = 'This is the set for x = %s\n---------------------------\n\nFor y=COLUMN %s we have\n%s\n%s\n%s\n%s\n%s\nEND of COLUMN 1 meas\n\nFor y=COLUMN 2 we have\n%s\n%s\n%s\n%s\n%s\nEND of COLUMN 2 meas\n\n';
fileID = fopen('new.txt','r');
A = fscanf(fileID,formatSpec,[4 Inf]);
A=A';

Now I have big matrix with all needed symbols. I took your data and get this:

A =

1001
1232
3ff3
4a45
23d4
5323
1232
3c43
4545
2d24
5a23
2001
2b23
1232
d387
6f74
4c47
354d
a546
3c63
5a46
a349
530 

So the last step is to divide this matrix at several. For example for your ArrayX:

ArrayX = A(1:11:end,1:3)
ArrayX =

100
200
530

I can't find some elegant way to divide A at number of columns as you wanted and just done the same way using loop.

Mikhail_Sam
  • 10,602
  • 11
  • 66
  • 102