MATLAB: How to extract numerical Datafrom txt-File with mixed string and numerical Data

numerical datastringstext filetextscan

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

Best Answer

fid=fopen('test.txt','rt');
k=0;
fline=fgetl(fid);
while ~feof(fid)
if strfind(fline,'GOTO/')
k=k+1;
temp=sscanf(fline(6:end),'%f,');
data(k,1:3)=temp';
fline=fgetl(fid);%skip the blank line
fline=fgetl(fid);
temp=sscanf(fline,'%f,');
data(k,4:6)=temp';
end
fline=fgetl(fid);
end
fclose(fid);