I like to read in the locations of oil platforms using this file in Matlab. I obtained the file from here. "Platform.gen" looks like this:
Id Lat Lon
1 0.100000000000000D+02 0.890000000000000D+02开发者_JS百科 2 -0.941577040000000D+02 0.294488400000000D+02 3 -0.941241560000000D+02 0.292748680000000D+02 4 -0.941225830000000D+02 0.292251370000000D+02 5 -0.943647730000000D+02 0.292845940000000D+02I read it into Matlab using:
[id lat lon]=textread('platform.gen','%s %s %s');
However, I am lost on how to decode the lat/lon values...help?
I would suggest instead using the conversion specifier %f
to read the values. This will automatically handle the format for the double-precision floating point numbers. The character D
is just another way to display scientific notation, so 0.10D+02
is 10
in double precision:
>> [id,lat,lon] = textread('platform.gen','%u %f %f','headerlines',1)
id =
1
2
3
4
5
lat =
10.0000
-94.1577
-94.1242
-94.1226
-94.3648
lon =
89.0000
29.4488
29.2749
29.2251
29.2846
Also, the function TEXTREAD will be removed in a future MATLAB version in favor of TEXTSCAN, which you could use like so:
>> fid = fopen('platform.gen','r');
>> data = textscan(fid,'%f %f %f','HeaderLines',1,'CollectOutput',true);
>> fclose(fid);
>> data{1}
ans =
1.0000 10.0000 89.0000
2.0000 -94.1577 29.4488
3.0000 -94.1242 29.2749
4.0000 -94.1226 29.2251
5.0000 -94.3648 29.2846
精彩评论