Extracting data from messy text file
古いコメントを表示
Data file attached. There is a header followed by row names. I want to extract the numeric data for Time, and Area and Volume then group them together into a convenient format for analysis. I've tried textscan, sscanf. I haven't regexp because I've never used it before! Many thanks in advance!
3 件のコメント
dpb
2014 年 7 月 14 日
Data file attached....
'Cepting it ain't... :)
Azzi Abdelmalek
2014 年 7 月 14 日
No file attached
Teresa Tutt
2015 年 4 月 14 日
Yes, please can someone post the "Data.txt" file?
採用された回答
その他の回答 (2 件)
Joseph Cheng
2014 年 7 月 14 日
編集済み: Joseph Cheng
2014 年 7 月 14 日
dpb's solution is much more elegant but thought i'd put what i did so far.
fid = fopen('Data.txt');
nlines = 1;
dashes = [];time=[]; timeline=[];
dataInd = 1;
while 1
tline = fgetl(fid);
if ~ischar(tline),break,end
if ~isempty(tline)& length(tline)>=2
switch tline(2:3)
case '--'
dashes = [dashes nlines];
case 'Ti'
timeline = [timeline nlines];
tTime= sscanf(tline,' Time [T] %f');
if isempty(tTime),continue, end;
Data(dataInd).time = tTime;
dataInd = dataInd +1;
case 'Ar'
tArea= sscanf(tline,' Area [V] %f%f%f')';
Data(dataInd).Area = tArea;
case 'Vo'
tVolume= sscanf(tline,' Volume [V] %f%f%f')';
Data(dataInd).Area = tArea;
case 'hM'
thmean= sscanf(tline,' hMean [L] %f%f%f')';
Data(dataInd).hMean = thmean;
end
end
nlines = nlines+1;
end
D. Ali
2019 年 4 月 27 日
0 投票
I have similar question where I need to extarct all MCAP amples with time they occured on in separat file and plot if possilbe
I attached the file
カテゴリ
ヘルプ センター および 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!