Reading and Processing Complex Data File

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 个)

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.

类别

帮助中心File 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