If LAT/LONG can really be anywhere in the file (not on 2nd line as shown in your sample), you could go for a regexp solution:
>> buf = fileread('myData.dat') ;
>> pat = 'LAT\s+(-?[\d\.])+\s+(-?[\d\.]+)\s+LONG\s+(-?[\d\.]+)\s+(-?[\d\.]+)' ;
>> tokens = regexp(buf, pat, 'tokens') ;
>> lat = str2double(tokens{1}(1:2))
lat =
50.0000 55.5100
>> long = str2double(tokens{1}(3:4))
long =
-40.0000 26.2600
There are thousands of ways to implement this with REGEXP; here is another possibility:
>> buf = fileread('myData.dat') ;
>> match = regexp(buf, '(?<=LAT\s+)-?[\d\.]+\s+-?[\d\.]+', 'match') ;
>> lat = str2num(match{1})
lat =
50.0000 55.5100
>> match = regexp(buf, '(?<=LONG\s+)-?[\d\.]+\s+-?[\d\.]+', 'match') ;
>> long = str2num(match{1})
long =
-40.0000 26.2600
Let me know if you want more information about how we are using REGEXP here.
Best Answer