MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   Matlab:丢失了奇怪的纬度格式 (https://www.labfans.com/bbs/showthread.php?t=26674)

poster 2019-12-14 20:46

Matlab:丢失了奇怪的纬度格式
 
我喜欢在Matlab中使用此[URL="http://www.gomr.boemre.gov/homepg/pubinfo/repcat/arcinfo/zipped/8322_ascii_platforms.pdf"]文件[/URL]来读取石油平台的位置。我从[URL="http://www.gomr.boemre.gov/homepg/pubinfo/repcat/arcinfo/index.html"]这里[/URL]获得文件。 “ 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:
[INDENT] [id lat lon] = textread('platform.gen','%s%s%s');

[/INDENT]但是,我不知道如何解码经/纬度值...帮助?



[B]回答:[/B]

我建议改用转换说明符%f读取值。这将自动处理双精度浮点数的格式。字符D只是显示[URL="http://www.math.hawaii.edu/lab/197/fortran/fort3.htm#double"]科学计数法的[/URL]另一种方式,因此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 此外,该功能[URL="http://www.mathworks.com/help/techdoc/ref/textread.html"]TEXTREAD[/URL]将有利于未来的MATLAB的版本中删除[URL="http://www.mathworks.com/help/techdoc/ref/textscan.html"]TEXTSCAN[/URL] ,您可以使用像这样:

>> 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

[url=https://stackoverflow.com/questions/5379984]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 23:24

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.