poster
2019-12-14, 20:46
我喜欢在Matlab中使用此文件 (http://www.gomr.boemre.gov/homepg/pubinfo/repcat/arcinfo/zipped/8322_ascii_platforms.pdf)来读取石油平台的位置。我从这里 (http://www.gomr.boemre.gov/homepg/pubinfo/repcat/arcinfo/index.html)获得文件。 “ Platform.gen”看起来像这样:
Id Lat Lon
1 0.100000000000000D + 02 0.890000000000000D + 02
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 + 02
我使用以下方法将其读入Matlab:
[id lat lon] = textread('platform.gen','%s%s%s');
但是,我不知道如何解码经/纬度值...帮助?
回答:
我建议改用转换说明符%f读取值。这将自动处理双精度浮点数的格式。字符D只是显示科学计数法的 (http://www.math.hawaii.edu/lab/197/fortran/fort3.htm#double)另一种方式,因此0.10D+02的双精度为10 :
>> [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 此外,该功能TEXTREAD (http://www.mathworks.com/help/techdoc/ref/textread.html)将有利于未来的MATLAB的版本中删除TEXTSCAN (http://www.mathworks.com/help/techdoc/ref/textscan.html) ,您可以使用像这样:
>> 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
更多&回答... (https://stackoverflow.com/questions/5379984)
Id Lat Lon
1 0.100000000000000D + 02 0.890000000000000D + 02
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 + 02
我使用以下方法将其读入Matlab:
[id lat lon] = textread('platform.gen','%s%s%s');
但是,我不知道如何解码经/纬度值...帮助?
回答:
我建议改用转换说明符%f读取值。这将自动处理双精度浮点数的格式。字符D只是显示科学计数法的 (http://www.math.hawaii.edu/lab/197/fortran/fort3.htm#double)另一种方式,因此0.10D+02的双精度为10 :
>> [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 此外,该功能TEXTREAD (http://www.mathworks.com/help/techdoc/ref/textread.html)将有利于未来的MATLAB的版本中删除TEXTSCAN (http://www.mathworks.com/help/techdoc/ref/textscan.html) ,您可以使用像这样:
>> 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
更多&回答... (https://stackoverflow.com/questions/5379984)