Pull numeric data from a mixed text file

1 visualizzazione (ultimi 30 giorni)
Birsen Ayaz-Maierhafer
Birsen Ayaz-Maierhafer il 9 Ago 2022
Risposto: Saffan il 7 Set 2023
Hi, I have a >15,000 row mixed data (numbers and strings). I want to pull some of the data from different parts of the text file. In the attached file I shortend the file shows only some of the lines I am interstsed. (There are thousonds of rows above these lines and lines between them as well).
  1. My first question is tabout the file extension of .o. How would I read this file (with extension of .o) without changing to . txt. The attached file has txt extension for the sake of this site but actually it is .o
  2. In the attached file I would like to pull some of the numeric values. How would I pull these numeric valuses when they are burried in the string rows?
Here is the numeric data I want to pull out from the test file in the attachment.
1.18, 0.00002,
7.9256-04 1.13 and the table values from
"gen time", "rossi-a", "b-eff" (both the estimate and the std val).
I am not intersted pull the string but the valuse in this problem.
3. I tried using readtable but I am not sure that is the right code to use. Any recommendations? I have about 220 files and I am going to pull the data for 220 files using a for loop. The values changes in each file.
Thank you

Risposte (1)

Saffan
Saffan il 7 Set 2023
Hi Birsen,
To read a file with “.o extension, you can use the fileread method as follows:
fileContent = fileread(filename);
To extract numeric data from a specific part of the file, you can identify the start and end indices of the section containing the desired data. In the provided file, the text "the final estimated combined collision" consistently appears, and the desired section is located after this text. Therefore, we can use it as a reference point. Here's an example:
startIndex = strfind(fileContent, 'the final estimated combined collision');
desiredFileContent = fileContent(startIndex :end);
Numeric values can then be extracted from the desired section using regular expressions and stored in appropriate data structures.
Please refer to this for more information:

Categorie

Scopri di più su Text Analytics Toolbox in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by