Pull numeric data from a mixed text file
1 回表示 (過去 30 日間)
古いコメントを表示
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).
- 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
- 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
0 件のコメント
回答 (1 件)
Saffan
2023 年 9 月 7 日
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:
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Text Analytics Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!