How to extract numbers from a header line
2 views (last 30 days)
Show older comments
Ok so I am trying to extract numbers from this header in a textfile that looks something along the lines of
Lead Number 1 Time Step .001 Data Points 6001
0
0
0
0
1.1
.34
ect.
This is my code so far:
filename = 'ecgnormal.txt';
delimiterIn = ' ';
headerlinesIn = 1
A = importdata(filename,delimiterIn,headerlinesIn);
data = (A.data);
header = A.textdata
Where data is all the data and header is now the top line of the file. How can I extract those numbers from the header line and assign them to variable?
0 Comments
Answers (1)
dpb
on 3 Oct 2014
>> A.header={'Lead Number 1 Time Step .001 Data Points 6001'};
>> fmt='Lead Number %f Time Step %f Data Points %f';
>> hdrVals=cell2mat(textscan(char(A.header),fmt,'collectoutput',1))
hdrVals =
1.0e+03 *
0.0010 0.0000 6.0010
>>
0 Comments
See Also
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!