Find the number after a string

5 visualizaciones (últimos 30 días)
Anton Fernando
Anton Fernando el 4 de Nov. de 2019
Comentada: Anton Fernando el 5 de Nov. de 2019
I have a text file containing data blocks. Those blocks are pretty much repetitive. They look like this (added two blocks in bold). There are around 50 blocks like this in the file.
P(22)
Standard Deviation of Fit : 0.00002
Amp 0.0266336611 8.772e-05
nu0 4159.5744620000 1.304e-04
glw 0.0166124171 3.044e-05
nlw 0.0000000000
4159.5695 0.02079 0.02075 0.00004
4159.5699 0.02172 0.02170 0.00002
4159.5704 0.02260 0.02260 0.00000
4159.5709 0.02342 0.02343 -0.00001
4159.5714 0.02416 0.02418 -0.00002
4159.5718 0.02482 0.02484 -0.00002
4159.5723 0.02539 0.02541 -0.00002
4159.5728 0.02586 0.02588 -0.00002
4159.5732 0.02622 0.02624 -0.00001
4159.5737 0.02648 0.02648 -0.00001
4159.5742 0.02661 0.02661 -0.00000
4159.5747 0.02663 0.02662 0.00001
4159.5751 0.02653 0.02652 0.00001
4159.5756 0.02631 0.02629 0.00002
4159.5761 0.02597 0.02595 0.00002
4159.5765 0.02552 0.02550 0.00002
4159.5770 0.02497 0.02495 0.00002
4159.5775 0.02432 0.02430 0.00001
4159.5780 0.02357 0.02357 0.00001
4159.5784 0.02275 0.02275 -0.00001
4159.5789 0.02185 0.02187 -0.00002
4159.5794 0.02089 0.02092 -0.00003
Integrated Cross Section (cm/molecule) : 1.537395e-20
Einstein A Coefficient (1/sec) : 2.097433e-01
R(23)
Standard Deviation of Fit : 0.00000
Amp 0.0237399264 1.270e-05
nu0 4331.0183720000 1.326e-05
glw 0.0166937170 2.409e-06
nlw 0.0000000000
4331.0146 0.02059 0.02058 0.00001
4331.0151 0.02128 0.02127 0.00000
4331.0155 0.02190 0.02190 -0.00000
4331.0160 0.02244 0.02244 -0.00000
4331.0165 0.02289 0.02290 -0.00000
4331.0169 0.02325 0.02326 -0.00000
4331.0174 0.02352 0.02352 -0.00000
4331.0179 0.02368 0.02368 0.00000
4331.0183 0.02374 0.02374 0.00000
4331.0188 0.02370 0.02369 0.00000
4331.0193 0.02354 0.02354 0.00000
4331.0198 0.02329 0.02329 0.00000
4331.0202 0.02294 0.02294 0.00000
4331.0207 0.02249 0.02249 0.00000
4331.0212 0.02196 0.02196 -0.00000
4331.0216 0.02134 0.02134 -0.00000
4331.0221 0.02065 0.02065 -0.00000
Integrated Cross Section (cm/molecule) : 2.026560e-20
Einstein A Coefficient (1/sec) : 2.747273e-01
I need two values from each block (bolded values).
From the first block;
P(22) and the number after the 'Integrated Cross Section (cm/molecule) :' which is 1.537395e-20.
From the second block;
R(23) and the number after the 'Integrated Cross Section (cm/molecule) :'. which is 2.026560e-20.
.....so on for all 50 blocks..
Any help is much appreciated.

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 4 de Nov. de 2019
Something like this:
s = string(fileread(your_file))
val = extractBetween(s, "Einstein A Coefficient (1/sec) :", newline)
double(val)

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by