Extracting numerical results from a text file at different positions
Show older comments
I have a number of output files to process, written out from Finite Element Analysis software, from which I need to extract data.
I need to extract data under 2 different "headings" from each of the files. However, each of the files has these headings at different rows. I have attached a "zipped" file with 2 files indicating this problem.
The following screenshots show the "headings" highlighted and the numerical data to be extracted, shown inside a "box":
First Heading

Second Heading

I have tried a number of options in Matlab, but I am overwhelmed as I am new to Matlab and programming.
Any assistance and guidance, would be much appreciated.
1 Comment
darova
on 10 Mar 2019
read about fileread, regexp
Accepted Answer
More Answers (1)
Gareth
on 10 Mar 2019
There is probably an easier way to do this... but this should help. (I am using R2018b).
a = fileread('0295_PhD_AB~Analysis 1.txt');
% find ( H A R M O N I C = \d )
[b,c] = regexp(a,'( H A R M O N I C = \d )','tokens');
result = table();
% find
for i = 1:length(c)
aux = (a(c(i)+586:c(i)+700));
d = regexp(aux,'([0-9.E-]*)','tokens');
result = [result;table(repmat(b{i},2,1),[d{2};d{7}])];
end
result
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!