Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: Extract numbers from table containing text and numbers
Replies: 29   Last Post: Feb 7, 2013 5:59 PM

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 Bruno Luong Posts: 9,822 Registered: 7/26/08
Re: Extract numbers from table containing text and numbers
Posted: Feb 3, 2013 4:59 AM
 Plain Text Reply

Rather work on fixed-field extraction method. I save a piece of your data in test.txt and here is how I read it back:

>> fid=fopen('test.txt','rt');
>> c=textscan(fid,'%s','Delimiter','\n')

c =

{6x1 cell}

>> fclose(fid);
>> s=char(c{1})

s =

Q (upper-edge --0.1250E-03 AmP )= 0.98880E-02+- 0.28300E-03 units/alpha/round
Q (upper-edge --0.2500E-03 AmP )= 0.19648E-01+- 0.39412E-03 units/alpha/round
Q (upper-edge --0.3750E-03 AmP )= 0.18384E-01+- 0.38318E-03 units/alpha/round
Q (upper-edge --0.5000E-03 AmP )= 0.17536E-01+- 0.37040E-03 units/alpha/round
Q (upper-edge --0.6250E-03 AmP )= 0.16064E-01+- 0.36000E-03 units/alpha/round
Q (upper-edge --0.7500E-03 AmP )= 0.15888E-01+- 0.35954E-03 units/alpha/round

>> firstcol = s(:,17:26)

firstcol =

0.1250E-03
0.2500E-03
0.3750E-03
0.5000E-03
0.6250E-03
0.7500E-03

>> data1 = str2num(firstcol)

data1 =

1.0e-03 *

0.1250
0.2500
0.3750
0.5000
0.6250
0.7500

% Do similar for other columns
% NOTE: textscan is NOT buggy when understand how it works

Bruno

Date Subject Author
1/31/13 Stan
1/31/13 Stan
2/1/13 Stan
2/1/13 dpb
2/1/13 Stan
2/2/13 dpb
2/2/13 dpb
2/2/13 Stan
2/2/13 dpb
2/2/13 Stan
2/2/13 dpb
2/3/13 dpb
2/3/13 dpb
2/3/13 Bruno Luong
2/3/13 dpb
2/3/13 Bruno Luong
2/3/13 dpb
2/3/13 dpb
2/4/13 Bruno Luong
2/4/13 dpb
2/4/13 dpb
2/5/13 Bruno Luong
2/5/13 dpb
2/5/13 Bruno Luong
2/5/13 dpb
2/5/13 dpb
2/3/13 Stan
2/3/13 Bruno Luong
2/7/13 Stan

© The Math Forum at NCTM 1994-2017. All Rights Reserved.