Data import processing doesn't import all of the data due to breaks with strings of words, need help with how to program it to skip words.
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Hi, i need to import this file. The name is 'test.dat' The issue is the machine i used put breaks in the middle of my data. So there are 4 or so per file (of which there are 100s). I just put up a sample. I need to figure out how to import the data in a series USING PROGRAMMING instead of Import data button. Any help would be appreciated.
Just to make sure and clarify, this is all in ONE file.
----------------------------------------------------------------------------
Data Header: Time:
40.015625 Sec 5/15/2013 4:58:32 PM
Data Acquisition: Timed
Time Axial Displacement Laser Axial Force
Sec mm V kN
19.952148 0.33294171 0.14016636 7.525351
19.961914 0.33293188 0.13982981 7.5288987
19.97168 0.33211958 0.14016636 7.5310717
19.981445 0.33200124 0.13949329 7.5342035
19.991211 0.33229405 0.14050288 7.5394435
20.000977 0.33361277 0.13982981 7.545064
20.010742 0.33254349 0.14050288 7.5489321
Data Header: Time: 40.015625 Sec 5/15/2013 4:58:34 PM
Data Acquisition: Timed
Time Axial Displacement Laser Axial Force
Sec mm V kN
20.020508 0.33314335 0.14117596 7.5557652
20.030273 0.33282167 0.14050288 7.5602489
20.040039 0.33306253 0.13982981 7.5675216
20.049805 0.33343881 0.14117596 7.5729542
20.05957 0.33403006 0.14083943 7.5809579
20.069336 0.33387816 0.14117596 7.582993
20.079102 0.33361062 0.14016636 7.5838275
20.088867 0.33440217 0.14016636 7.5888386
1 Comment
Matt Kindig
on 4 Jun 2013
Edited: Matt Kindig
on 4 Jun 2013
Do you need any of the information in the "break" lines? I assume the breaks are (for example):
Data Header: Time: 40.015625 Sec 5/15/2013 4:58:34 PM
Data Acquisition: Timed
Time Axial Displacement Laser Axial Force
Sec mm V kN
If not, I think you can use regular expressions to do it. Assuming your file is not too big (as to not run out of memory), you could try this:
myfile = fileread('test.dat');
pattern = '(([\d\.]+)(\s+)){4}\n';
goodlines = strtrim(regexp(myfile, pattern, 'match')); %isolate only "good" lines
data = regexp(goodlines', '\s+', 'split'); %split by space
data = cell2mat( cellfun(@str2double, data, 'uni', false)); %convert to double
Answers (1)
per isakson
on 10 Jun 2013
0 votes
This question is closed.
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!