Collect information of a file with the same kind of text pattern
Dear all
I have the same kind of text file that I am attaching to this question in different folders in my MatLab path. As you can see, from line 42 to the end of the file, there are text blocks like:
Cr1 Cr2 ( 0, 0, 0) 2.6832 ( 0.000, -4.001, 0.000) 4.001
J_iso: 2.6832
[Testing!] Jprime: 10.082, B: -4.132
[Testing!] DMI: ( 0.0635 0.0000 -0.0306)
[Testing!]J_ani:
[[-1.401 0. 0.396]
[ 0. -0.327 0. ]
[ 0.396 0. -8.263]]
I would be interested in MatLab collecting information from this kind of patterns as follows:
As you can see, at the end of the first line of the text block that I put before as an example, the number 4.001 can be found. There are other text blocks with the last element of the first line ending in that specific number, but also on other values, like 6.930. It would be great if for each occurrence of the element 4.001 (and also for 6.930) as the last element of the first line of a text block MatLab creates a line with the following information in a line:
(i) First column: number index of the first Crx appearance (in the example above, 1)
(ii) Second column: number index of the second Crx appearance (in the example above, 2)
(iii) Third to fifth columns: the three elements in the first parenthesis of the first line (in the example above, 0 0 0)
(iv) Sixth to eighth columns: the three elements inside the parenthesis of the fourth line of the text block (that it is, what it is after the text "[Testing!] DMI:". In this case, 0.0635 0.0000 -0.0306).
So first line would be 1 2 0 0 0 0.0635 0.0000 -0.0306. Same for all the occurrences of 6.930 as the last element of the first line of the text blocks.
Any idea on how to do this efficiently?Dear all
I have the same kind of text file that I am attaching to this question in different folders in my MatLab path. As you can see, from line 42 to the end of the file, there are text blocks like:
Cr1 Cr2 ( 0, 0, 0) 2.6832 ( 0.000, -4.001, 0.000) 4.001
J_iso: 2.6832
[Testing!] Jprime: 10.082, B: -4.132
[Testing!] DMI: ( 0.0635 0.0000 -0.0306)
[Testing!]J_ani:
[[-1.401 0. 0.396]
[ 0. -0.327 0. ]
[ 0.396 0. -8.263]]
I would be interested in MatLab collecting information from this kind of patterns as follows:
As you can see, at the end of the first line of the text block that I put before as an example, the number 4.001 can be found. There are other text blocks with the last element of the first line ending in that specific number, but also on other values, like 6.930. It would be great if for each occurrence of the element 4.001 (and also for 6.930) as the last element of the first line of a text block MatLab creates a line with the following information in a line:
(i) First column: number index of the first Crx appearance (in the example above, 1)
(ii) Second column: number index of the second Crx appearance (in the example above, 2)
(iii) Third to fifth columns: the three elements in the first parenthesis of the first line (in the example above, 0 0 0)
(iv) Sixth to eighth columns: the three elements inside the parenthesis of the fourth line of the text block (that it is, what it is after the text "[Testing!] DMI:". In this case, 0.0635 0.0000 -0.0306).
So first line would be 1 2 0 0 0 0.0635 0.0000 -0.0306. Same for all the occurrences of 6.930 as the last element of the first line of the text blocks.
Any idea on how to do this efficiently? Dear all
I have the same kind of text file that I am attaching to this question in different folders in my MatLab path. As you can see, from line 42 to the end of the file, there are text blocks like:
Cr1 Cr2 ( 0, 0, 0) 2.6832 ( 0.000, -4.001, 0.000) 4.001
J_iso: 2.6832
[Testing!] Jprime: 10.082, B: -4.132
[Testing!] DMI: ( 0.0635 0.0000 -0.0306)
[Testing!]J_ani:
[[-1.401 0. 0.396]
[ 0. -0.327 0. ]
[ 0.396 0. -8.263]]
I would be interested in MatLab collecting information from this kind of patterns as follows:
As you can see, at the end of the first line of the text block that I put before as an example, the number 4.001 can be found. There are other text blocks with the last element of the first line ending in that specific number, but also on other values, like 6.930. It would be great if for each occurrence of the element 4.001 (and also for 6.930) as the last element of the first line of a text block MatLab creates a line with the following information in a line:
(i) First column: number index of the first Crx appearance (in the example above, 1)
(ii) Second column: number index of the second Crx appearance (in the example above, 2)
(iii) Third to fifth columns: the three elements in the first parenthesis of the first line (in the example above, 0 0 0)
(iv) Sixth to eighth columns: the three elements inside the parenthesis of the fourth line of the text block (that it is, what it is after the text "[Testing!] DMI:". In this case, 0.0635 0.0000 -0.0306).
So first line would be 1 2 0 0 0 0.0635 0.0000 -0.0306. Same for all the occurrences of 6.930 as the last element of the first line of the text blocks.
Any idea on how to do this efficiently? text patterns MATLAB Answers — New Questions