필터 지우기
필터 지우기

Pull numeric data from a mixed text file

조회 수: 3 (최근 30일)
Birsen Ayaz-Maierhafer
Birsen Ayaz-Maierhafer 2022년 8월 9일
답변: Saffan 2023년 9월 7일
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

답변 (1개)

Saffan
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:

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by