How to extract numerical Datafrom txt-File with mixed string and numerical Data
Show older comments
Hello Community,
I have a txt-File with APT-Code for a 5-axis Millingmachine. It looks like this:
PARTNO/0
UNITS/MM
MCS/$
1.0000000000,0.0000000000,0.0000000000,$
0.0000000000,1.0000000000,0.0000000000,$
0.0000000000,0.0000000000,1.0000000000,$
-0.000000,-0.000000,-0.000000
MULTAX/ON
CUTTER/12.000000,0.000000
LOADTL/1,LENGTH,0.000000,OSETNO,0
SPINDL/RPM,796,CLW
COOLNT/FLOOD
SELECT/0
FEDRAT/MMPM,79.577499
GOTO/-11.132475,124.105644,13.006427,$
-0.0131792286,0.9844993949,0.1748921126
GOTO/-11.099527,121.644394,12.569197,$
-0.0131792286,0.9844993949,0.1748921126
FEDRAT/MMPM,159.154907
GOTO/-11.113749,121.604874,12.790616,$
-0.0131792286,0.9844993949,0.1748921126
GOTO/-11.122633,121.413193,13.868834,$
-0.0131792286,0.9844993949,0.1748921126
GOTO/-11.031648,121.223442,14.943585,$
-0.0131792286,0.9844993949,0.1748921126
GOTO/-10.841551,121.037193,16.005919,$
-0.0131792286,0.9844993949,0.1748921126
FEDRAT/MMPM,79.699799 ...........
I'am only interested at the three numbers behind GOTO/ and the three in the next line. I want to get them into a Matrix [n,6]. I tried some things with textscan but not succesful. Can anyone give me a short description how to deal with the mixed Data?
MfG jan
1 Comment
Fangjun Jiang
on 10 Aug 2011
Please re-format your content in the text file using the "{}Code" button. It's not clear now where is the line.
Accepted Answer
More Answers (1)
Walter Roberson
on 10 Aug 2011
Doesn't anyone ever use "sed" anymore?
!sed -e "g/^GOTO/.,.+1p" < test.txt > compactinfo.txt
On unix systems, the result would be a file that had just the GOTO and following line, ready to parse.
We are not actually required to use MATLAB for all of the work, if there are more appropriate tools.
Categories
Find more on Text Files 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!