Extracting data from messy text file

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!

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

It’s just a repetitive application of textscan…

fmt1='Time       [T] %f';
fmt2='Area [V] %f %f %f Volume [V] %f %f %f';
fid=fopen('Data.txt');
% read first set as has unique number header lines
time=cell2mat(textscan(fid, fmt1,'headerlines',10)); % 1st time value
data=cell2mat(textscan(fid, fmt2, ...
'headerlines',3,'collectoutput',true,'delimiter','\n'))
% and second also has unique number to skip...
time=[time; cell2mat(textscan(fid, fmt1,'headerlines',5))];
data=[data; cell2mat(textscan(fid, fmt2, 'headerlines',3, ...
'collectoutput',true,'delimiter','\n'))];
while ~feof(fid)
time=[time; cell2mat(textscan(fid, fmt1,'headerlines',7))];
data=[data; cell2mat(textscan(fid, fmt2, 'headerlines',3, ...
'collectoutput',true,'delimiter','\n'))];
end
fid=fclose(fid);

At the end you’ll have a Nx1 vector of time and Nx6 of volumes and areas. You could either concatenate time and data into one array or separate out A and V based on the columns in data; your choice.

At the command line the above gives me

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Technical Source

Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.