Reading and Processing Complex Data File

조회 수: 5 (최근 30일)
Abhimanyu Jamwal
Abhimanyu Jamwal 2017년 2월 10일
답변: Star Strider 2017년 2월 10일
Hey,
I have a Tecplot data file which has point information about different slices of a wing. So the information that I want to extract from the .dat file is in different sections of the file. The structure of the file is something like this:
Line 1-12 - information about the file I don't want ;; Line 12 - 358 - 5 columns of real values i.e. information I want ;; Line 359 - 707 - again numbers I don't want as 2 columns ;; Line 708 - 1054 - 5 columns of real values i.e. information I want ;; ...and the same pattern repeats
I have attached the file for better understanding.
Now since I have many such data files I wanted to write a code where for each file I can just extract the required data in the given line numbers. The format of each data file is the same.
Any help as to how should I go about it would be appreciated.
Thanks

답변 (1개)

Star Strider
Star Strider 2017년 2월 10일
This seems to work:
fidi = fopen('a10-extended-fine-coupled-wing-x-wall shear stress-cp.txt','rt');
k1 = 1;
while ~feof(fidi)
C = textscan(fidi, '%f%f%f%f%f', 'HeaderLines',11, 'CollectOutput',1);
M = cell2mat(C);
if isempty(M)
break
end
D{k1} = M(~isnan(M(:,3)),:);
fseek(fidi, 0, 0);
k1 = k1 + 1;
end
Note: The collected and edited data are in the ‘D’ cell array.

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by