登录论坛

查看完整版本 : 使用URL将数据读入Matlab


poster
2019-12-10, 20:48
我想将Weather Unground的天气数据直接读取到Matlab中。对于给定的站点,您可以选择以逗号分隔格式输出数据。如何编写将信息读入Matlab的Matlab函数?我不想下载文件,而是从URL读入。

例如,这是一些数据的URL (http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=MC9780&format=1) 。是否有一些Matlab函数以URL作为输入并从那里找到的数据保存数据?



回答:

函数URLREAD (http://www.mathworks.com/help/techdoc/ref/urlread.html)是您要寻找的。例如,使用上面的URL将给出以下输出:

>> str = urlread('http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=MC9780&format=1'); str = Time,TemperatureF,DewpointF,PressureIn,WindDirection,WindDirectionDegrees,WindSpeedMPH,WindSpeedGustMPH,Humidity,HourlyPrecipIn,Conditions,Clouds,dailyrainin,SoftwareType
2010-09-27 00:09:00,56.0,52.0,30.05,NNE,25,0.0,3.0,86,0.00,,,0.00,,
2010-09-27 00:17:00,56.0,52.0,30.05,NNE,25,0.0,3.0,86,0.00,,,0.00,,
2010-09-27 00:28:00,56.0,52.0,30.04,NNE,30,2.0,5.0,85,0.00,,,0.00,,
... 现在,您只需解析字符串输出即可获取所需的信息。

如果您希望从URL读取并将其保存到文件中,而不是将其作为字符串变量加载,则可以使用URLWRITE (http://www.mathworks.com/help/techdoc/ref/urlwrite.html)函数。



更多&回答... (https://stackoverflow.com/questions/3807096)