Reading ascii data with headers

9 visualizaciones (últimos 30 días)
Martin Leclerc
Martin Leclerc el 1 de Abr. de 2015
Comentada: Martin Leclerc el 1 de Abr. de 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

Respuesta aceptada

Stephen23
Stephen23 el 1 de Abr. de 2015
Editada: Stephen23 el 1 de Abr. de 2015
Why not just use fgetl and textscan instead to load the data:
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
  1 comentario
Martin Leclerc
Martin Leclerc el 1 de Abr. de 2015
Hi Stephen,
Thanks a lot, it works just fine!
Regards,
Martin

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Large Files and Big Data en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by