data extraction from f06 file

4 次查看(过去 30 天)
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!

采纳的回答

Mathieu NOE
Mathieu NOE 2022-6-29
hello my friend
here you are
the result is stored in Result_c
clc
clearvars
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;
end
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;
end
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)
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by