Reputation: 919
I would like to have an m-file that will be able read a text file and store each set of data into separate arrays. A set of data is a range of hex values appeared between specific strings.
The format of the text file is similar to the following:
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
---------------------------
..........
..........
As you can see, for each new value of X, I get a separate set of data for "y=COLUMN 1" and for "y=COLUMN 2". What I want is to store these data sets (the two 'y') into separate (1,2) arrays, one for each X value. Ideally, this will look like that:
Array_for_x_100(1,1)=[data for "y=COLUMN 1"]
Array_for_x_100(1,2)=[data for "y=COLUMN 2"]
Array_for_x_200(1,1)=[data for "y=COLUMN 1"]
Array_for_x_200(1,2)=[data for "y=COLUMN 2"]
..........
..........
What I thought was the use of textscan for doing that but I got a bit confused as how to use it. I somehow have to store the range of values appeared between specific strings (e.g. store the values appear 3 lines after "This is the set for x = 100" string until "END of COLUMN 1 meas" string, etc.).
If anyone can help, I will really appreciate it.
Upvotes: 0
Views: 238
Reputation: 20056
Try tweaking the parameters of TextScan
fid = fopen([opath filename]);
K = textscan(fid,'%f %f %f %f ',...
'CommentStyle','For',...
'CommentStyle','This',...
'CommentStyle','End',...
'Delimiter',',\t',...
'MultipleDelimsAsOne',1);
fclose(fid);
K = cell2mat(K);
You may adjust it, find more parameters to control your input, etc. But it should work, with some sweat on your side
Upvotes: 0