I'm trying to write a function to read multiple (1000+) text files ('.txt') into MATLAB. A snippit of one file is shown below. The actual file has the same columns but with ~150 000 rows.
Start, Serial, DeviceId, RunNumber, Date, Real, Elapsed, X, EcgVal, EcgStatus, CapnoVal, CapnoStatus, P1Val, P1Status, P2Val, P2Status, P3Val, P3Status, Spo2Val, Spo2Status, CprDepth, CprFrequency, CprStatus, CprWaveVal, FiltEcgVal, FiltEcgStatus, Ecg2Val, Ecg2Status, Ecg3Val, Ecg3Status, Ecg4Val, Ecg4Status
2013-01-01 23:51:12, 00017711, TEMS ACP272, , 01-01-2013, 23:51:12.000, 00:00:00.000, 41275.993889, 0.000000, -1, 0.000000, 0, 0.000000, 0, 0.000000, 0, 0.000000, 0, 0.000000, 0, 0.000000, 0, 0, 0.000000, 0.000000, 1, 0.000000, 1, 0.000000, 1, 0.000000, 1
2013-01-01 23:51:12, 00017711, TEMS ACP272, , 01-01-2013, 23:51:12.008, 00:00:00.008, 41275.993889, 0.000000, -1, 0.000000, 0, 0.000000, 0, 0.000000, 0, 0.000000, 0, 0.000000, 0, 0.000000, 0, 0, 0.000000, 0.000000, 1, 0.000000, 1, 0.000000, 1, 0.000000, 1
2013-01-01 23:51:12, 00017711, TEMS ACP272, , 01-01-2013, 23:51:12.016, 00:00:00.016, 41275.993889, 0.000000, -1, 0.000000, 0, 0.000000, 0, 0.000000, 0, 0.000000, 0, 0.000000, 0, 0.000000, 0, 0, 0.000000, 0.000000, 1, 0.000000, 1, 0.000000, 1, 0.000000, 1
2013-01-01 23:51:12, 00017711, TEMS ACP272, , 01-01-2013, 23:51:12.024, 00:00:00.024, 41275.993889, 0.000000, -1, 0.000000, 0, 0.000000, 0, 0.000000, 0, 0.000000, 0, 0.000000, 0, 0.000000, 0, 0, 0.000000, 0.000000, 1, 0.000000, 1, 0.000000, 1, 0.000000, 1
I've tried the obvious approaches (csvread, dlmread, importdata) without success. When I open this file using the 'ImportData' function I get:
þS
followed by 5 blank lines. Using
fid = fopen('TEST.txt','r');
fgetl(fid)
I find that there is an empty row between each data row and that there is a space between each character.
I've also tried using the textscan function as follows
fid = fopen('TEST.txt','r');
c = textscan(fid, '%s', 'Delimiter', ',')
but this returns an empty cell.
An alternative that does work is to open the file in Excel and save it as a CSV file. However, given that I am trying to do this for 1000+ files, this is not feasible.
Any comments, suggestions, or advice is greatly appreciated. Thank you!
UPDATE:
The following seems to work:
data = textscanu('TEST.txt');
str=textscan(data{1},'%s','Delimiter',',')
I will try to write this up in general to read the entire file, skip blank lines, and organize all the columns.
N x 32sized cell array for each text file? - Divakar