フィルターのクリア

How can I get only damping and frequency column?

1 回表示 (過去 30 日間)
Milind Amga
Milind Amga 2022 年 6 月 15 日
コメント済み: Karim 2022 年 6 月 17 日
My aim is to extract only numeric values in Damping and Frequency column only. The file, from which I am trying to extract data is very large and contains special character, numbers, text and empty lines. Can anyone please suggest me an efficient way to extract the required data?
I hope the images below gives you a better understanding of the data file. Thanks in advance!!
  2 件のコメント
Mathieu NOE
Mathieu NOE 2022 年 6 月 15 日
hello
can you zip the file and try to share it (maybe with Google drive or alike)
Milind Amga
Milind Amga 2022 年 6 月 15 日
編集済み: Milind Amga 2022 年 6 月 15 日
Here you go :text_file (file has been unlinked later)
You can use notepad to open this file.

サインインしてコメントする。

採用された回答

Karim
Karim 2022 年 6 月 15 日
編集済み: Karim 2022 年 6 月 15 日
Hi,
One approach is to read the whole file, seek some specific line, from that line read the data with a delimiter.
See below for the code, note that i changed the extention to .txt in order to run the demo on the site. It will work fine if you chage the fileID to 'flutter_2d_rh_wing_base.f06'
Best regards
fileID = fopen('flutter_2d_rh_wing_base.f06.txt');
% read the whole file, interpret each line as a string
MyText = textscan(fileID, '%s%[^\n\r]', 'Delimiter', '', 'WhiteSpace', '', 'ReturnOnError', false);
% convert the cell array into a string array, for easier indexing
MyText = string(strtrim(MyText{1}));
% use some logic to find the usefull data blocks
% first the start locations
StartLineIdx = contains(MyText, "KFREQ 1./KFREQ VELOCITY DAMPING FREQUENCY COMPLEX EIGENVALUE");
StartLineIdx = find(StartLineIdx) + 1;
% now find the stop locations of each data block
StopLineIdx = contains(MyText, "1 MSC.NASTRAN JOB CREATED ON");
StopLineIdx = find(StopLineIdx) - 1;
% remove some indices that occur before the first start index
StopLineIdx(StopLineIdx<StartLineIdx(1)) = [];
% convert the locations into a single logical array
GetMe = false(size(MyText,1),1);
for i = 1:numel(StartLineIdx)
GetMe(StartLineIdx(i):StopLineIdx(i)) = true;
end
% extract the usefull strings from the data
MyData = MyText(GetMe);
% exchange double spaces into a single space
MyData = regexprep(MyData, '\s+', ' ');
% use the spaces to split each string
MyData = split(MyData,' ');
% convert the strings into a numeric array
MyData = str2double(MyData);
% extract the columns of intrest
MyDamp = MyData(:,4);
MyFreq = MyData(:,5);
  6 件のコメント
Milind Amga
Milind Amga 2022 年 6 月 17 日
@KASR Could you please remove the txt file that you have attached in your previous response.
Karim
Karim 2022 年 6 月 17 日
yes sure, i only added it so that the demo code would work.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by