reading a complex txt file

1 回表示 (過去 30 日間)
Arash
Arash 2011 年 6 月 20 日
[EDIT: 20110620 14:20 CDT - reformat - WDR]
I want to read a text file as below and use it in an iterative manner, after reading and making some changes I need to write it as a text file and then use it for the next iteration, the file consists of 6 sections, that I copied a couple of lines for each section below. I appreciate it if someone can help me with this.
the 1st section is just one line showing 1,
the 2nd section is again one line showing 0.00. these two sections are always the same.
the 3rd section always contains 5388 lines with 4 fields (always 4 fields).
number of lines in the 4th section is not fixed but can be found: the number of lines in the 4th section can be found from the elements with values of 4 or 5 in the 2nd field of the 3rd section PLUS some additional lines for each, in other words, each 4 or 5 (from section 3-field 2) forms a couple of 10-field line in section 4 (always 10) the number of generated 10-field lines equals the value of the 3rd field of the corresponding 4-field line in the 3rd section, and about additional lines, the 6th field of the 10-field lines shows the number of additional lines that are added right after the 10-field lines, these additional lanes can have different numbers of fields from min:5 to max:8 (the exact number of fields can be found from the 4th field of the additional lines),
the 5th section is just one line of string data,
the 6th section is somehow similar to section 4: the number of lines in this section equals the total number of elements with values of 6 in the 2nd field of the 3rd section PLUS some additional lines for each, in other words, each 6 (from section 3-field 2) forms a 3-field line in section 6 (always 3 fields), and about additional lines, for each 3-field line, 2 lines are added (always 2), the number of fields of the first added line equals 2*(the value of the 2nd field in the corresponding 3-field line), and the number of fields of the second added line equals 2*(the value of the 3rd field in the corresponding 3-field line),
here is a better sample: (the 1st field of the 3rd section (1,6,75,5075,5214) shows IDs so they can be traced in the sections 4 and 6)
1
0.00
1 5 4 180
6 1 0 0
75 6 0 0
5075 4 4 105
5214 6 0 0
1 1 32 5 4 1 4 0 0 0
4 1 1 3 7062 6493 16015
1 2 32 5 4 1 6493 0 0 0
6493 1 2 3 16015 4 7062
1 3 32 5 4 1 7062 0 0 0
7062 1 3 3 6493 16015 4
1 4 64 5 4 1 16015 0 0 0
5075 1 76 10 7 2 5077 6060 0 0
5077 5075 1 2 6059 5074
6060 5075 1 2 5074 6059
5075 2 76 32 7 2 5077 6060 0 0
5077 5075 2 2 6060 5074
6060 5075 2 2 5077 6059
5075 3 76 25 7 1 5074 0 0 0
5074 5075 3 3 5077 6059 6060
5075 4 76 10 7 1 6059 0 0 0
6059 5075 4 3 6060 5074 5077
=======Two Way Stop Signs/Yield Signs Below =======
75 2 2
750 75 6186 75
76 75 6182 75
5214 2 3
5237 5214 5255 5214
440 5214 5224 5214 5258 5214
I want to change some values in the 3rd section that consequently will change some parts of the data in the 4th and 6th sections, and finally I want to write this file in the same format, then again from the beginning so I’d like to use this file in an iterative process, at each iteration I need to read the file and after some modifications, write it for the next iteration.
  1 件のコメント
Walter Roberson
Walter Roberson 2011 年 6 月 20 日
I am not sure why you do not read the file in, perform _all_ of the iterations, and then write it out only once?

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by