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

2 visualizaciones (últimos 30 días)
Abhishek Goswami
Abhishek Goswami el 14 de Abr. de 2022
Editada: Moksh el 29 de Sept. de 2023
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.

Respuestas (1)

Moksh
Moksh el 27 de Sept. de 2023
Editada: Moksh el 29 de Sept. de 2023
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

Categorías

Más información sobre Text Data Preparation en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by