how to extract number from a .dat file and assign it to an excel sheet cell?

21 views (last 30 days)
Adarsh Vasa
Adarsh Vasa on 3 Feb 2020
Commented: Adarsh Vasa on 3 Feb 2020
I am using Fluent to extract surface integral values that are saved with a significant amount of text and the required numerical value. It looks like the following :
"Surface Integral Report"
Average of Surface Vertex Values
Wall Shear Stress (pascal)
-------------------------------- --------------------
wall 0.047597805
I would like to write a code to extract this numerical value, '0.047597805' from above .dat file and save it into a cell in an excel sheet ('.csv' or '.xlsx'). Please help!!

Accepted Answer

Bhaskar R
Bhaskar R on 3 Feb 2020
Edited: Bhaskar R on 3 Feb 2020
Assuming your a.dat file is with data
"Surface Integral Report"
Average of Surface Vertex Values
Wall Shear Stress (pascal)
-------------------------------- --------------------
wall 0.047597805
Then your code
T = readtable('a.dat'); % read data to table
T.Properties.VariableNames = {'Wall_Shear_Stress', 'pascal'}; % modify variable names
writetable(T, 'Reposrt.csv'); % write to csv/excel file
  3 Comments
Adarsh Vasa
Adarsh Vasa on 3 Feb 2020
Thank you so much. It worked like a beauty. I got late in responding as I had to upgrade to the 2019 version, in order to use readmatrix function. Thanks again.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!