How to extract numerical values as a table from an .out (text) file ?

조회 수: 2 (최근 30일)
Abhishek Goswami
Abhishek Goswami 2022년 4월 14일
편집: Moksh 2023년 9월 29일
I am using an old Fortan based solver for CFD analysis. The output from the software is an .out text file. I want to know how to extract the useful values from this text file. From the attached file I would like to extract values of x,y,z and s0 for different Mach Numbers and angle of attacks. The useful values start in the row 761, and are further characteristized for different mach numbers and angle of attacks. I would like the code to extract the value of mach number and angle of attack, and x, y, z and s0 for every mach number and angle of attack.

답변 (1개)

Moksh
Moksh 2023년 9월 27일
편집: Moksh 2023년 9월 29일
Hi Abhishek,
I understand that you have performed a CFD analysis and obtained the resulting data in “.txt” format. Now you are looking to extract the data relevant to you which starts from line 761.
You can try utilizing the “fopen” and “textscan” functions in MATLAB, which opens a text file and reads it into a “cell array” respectively. Additionally, you can specify conversion specifiers in textscan” function to match the data while reading.
For an example, you can try implementing the data into a cell array where each index corresponds to that line in the text file using the above-mentioned functions.
Please refer to the following code snippet and use the path for "data.txt" in the "fopen" function:
% Reading the sample text file
fid = fopen('data.txt');
% Reading the text data inside the file
s = textscan(fid, '%s', 'Delimiter','\n');
% s now contains the file in cell-array format
s = s{1};
% Displaying data on line 761
disp(s{761})
Extraction of the relevant data can now be achieved by simply looping over the cell array.
For more information, please refer to the following documentation:
Hope this helps in resolving the issue you were facing.
Best Regards,
Moksh Aggarwal

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by