Accelerometer data file correction

2 views (last 30 days)
Hi,
My accelerometer writes a .csv log file continuously for 24 h a day that I read into Matlab with the importdata function. Those files contain 10 header lines beginning with a semicolon and the rest is numerical data organized into 4 columns (time,x-axis acceleration, y-axis, z-axis).
My new sensors write an error line sometimes into the data section which also start with a semicolon. Therefore, the importdata function stops reading the data at the point where the error message appears.
Could you please help me in solving this question? I want to read in the file, delete the error message lines and save the file with its original name. csvread and dlmread were not useful in solving this question.
Thanks!

Accepted Answer

Walter Roberson
Walter Roberson on 3 Oct 2011
There are multiple ways. One way is:
filestr = fileread('YourData.csv');
filestr = regexprep(filestr, '^;.*$\n', '', 'lineanchors', 'dotexceptnewline');
fid = fopen('YourNewData.csv','w');
fwrite(fid, filestr);
fclose(fid)
  3 Comments
Walter Roberson
Walter Roberson on 3 Oct 2011
filestr = regexprep(filestr, '^;.*$', 'NaN,NaN,NaN,NaN', 'lineanchors', 'dotexceptnewline');
That would introduce placeholders for the missing data, allowing you to use any available function to interpolate data in place of NaN.
One point that I would question is whether an error message always replaces _exactly_ one point ? If several might be replaced, then linear interpolation would not be suitable as the number of missing points would not be known. The code I give here will replace each error message with one row of NaN, which will help if each there is one error message per missing point.
My first guess would be that error messages in the log would tend to be associated with extreme acceleration values -- times at which the continuity of the acceleration data would be least likely ?

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import and Export in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!