Reading ascii data with headers
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Martin Leclerc
am 1 Apr. 2015
Kommentiert: Martin Leclerc
am 1 Apr. 2015
Hi,
I am trying to read an ascii file with importdata function. The separator is tabulator (\t).
Data_and_Headers = importdata(DataTxTfile, '\t');
All_Data = Data_and_Headers.data;
Titles = Data_and_Headers.textdata(1,:);
Units = Data_and_Headers.textdata(2,:);
There are 2 header's rows. The first row is the title and the second is the units. Numeric values starts at the third row. The reading of the numeric data and units works fine but title's reading is not working. I have 31 columns and all the column's titles are regrouped in the first cell while the remaining 30 are empty. It seems that the tabulator is not used for title row but works fine for the remaining.
Any suggestions?
Ascii file is attached.
Thanks for your help.
Martin
0 Kommentare
Akzeptierte Antwort
Stephen23
am 1 Apr. 2015
Bearbeitet: Stephen23
am 1 Apr. 2015
fid = fopen('Acquisition.txt','rt');
hdr = strtrim(regexp(fgetl(fid),'\t','split'));
unt = strtrim(regexp(fgetl(fid),'\t','split'));
mat = cell2mat(textscan(fid,repmat('%f',1,numel(hdr))));
fclose(fid);
This imports the uploaded file and produces these variables:
>> hdr(:)
ans =
'Time'
'X Displ (abs)'
'Y Displ (abs)'
'Z Displ (abs)'
'RX Displ (abs)'
...
'ABS Act Z-NW Displacement'
'ABS Act Z-NW Force'
'ABS Act Z-SE Displacement'
>> unt(:)
ans =
'sec'
'mm'
'mm'
'mm'
'rad'
'rad'
'rad'
'kN'
...
'kN'
'mm'
'kN'
'ABS Act Z-SE Force'
'ABS Act Z-SW Displacement'
'ABS Act Z-SW Force'
and of course all 46 rows of the numeric data:
>> whos mat
Name Size Bytes Class Attributes
mat 46x31 11408 double
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!