data extraction from f06 file

4 views (last 30 days)
Milind Amga
Milind Amga on 29 Jun 2022
Commented: Mathieu NOE on 4 Jul 2022
Can anyone help me out in extracting the data highlighted in yellow? The data highlighted is part of matrix of order 5X5. Each line of data is a column of the matrix, for example, the first highlighted data line is the first column of a 5X5 matrix and each data point consists of a real part and a imaginary part seperated by comma.
I am attaching the file here (link removed later) for reference and the data other than that is of no use right now.
If you could create 5X5X16 matrices from the data (a seperate matrix for real part and a seperate matrix for imaginary part) that would be great.
Thanks in advance!

Accepted Answer

Mathieu NOE
Mathieu NOE on 29 Jun 2022
hello my friend
here you are
the result is stored in Result_c
fileID = fopen('flutter_2d_rh_wing_base.f06');
Raw = textscan(fileID, '%s%[^\n\r]', 'Delimiter', '', 'WhiteSpace', '', 'ReturnOnError', false);
Raw = string(strtrim(Raw{1}));
Line1 = contains(Raw, "MATRIX QHH");
Line1 = find(Line1) + 3;
Line2 = contains(Raw, "THE NUMBER OF NON-ZERO TERMS");
Line2 = find(Line2) - 1;
Line2(Line2<Line1(1)) = [];
Take = false(size(Raw,1),1);
for i = 1:numel(Line1)
ind = Line1(i):3:Line2(i); % every 3 lines
Take(ind) = true;
Out = Raw(Take);
Out = regexprep(Out, ',', ' ');
% fill a 5x5x16 matrice
count1 = 0;
count2 = 1;
for ci = 1:size(Out,1)
if count1>4
count1 = 0;
count2 = count2 +1;
count1 = count1 +1;
tmp = split(Out(ci,1),' ');
tmp = tmp(2:end); % remove "1)"
tmp = tmp(strlength(tmp) > 0);
tmp = str2double(tmp);
Result_c(:,count1,count2) = tmp(1:2:end) + 1i*tmp(2:2:end); % real + j*imaginary part (comma separated values)
Mathieu NOE
Mathieu NOE on 4 Jul 2022
as always, my pleasure !

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!