Reading ascii data with headers
12 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Stephen23
2015 年 4 月 1 日
編集済み: Stephen23
2015 年 4 月 1 日
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Large Files and Big Data についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!