tags:

views:

82

answers:

2

I want to read weather data from Weather Unground into Matlab directly. For a given site you can select to output the data in comma delimited format. How can I write a Matlab function that will read in the information into Matlab? I don't want to download the file but rather read it in from the URL.

For example, here is a URL of some data. Is there some Matlab function that has a URL as an input and saves data from whatever it finds there?

+4  A: 

The function URLREAD is what you're looking for. For example, using your URL above gives the following output:

>> 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<br>
2010-09-27 00:09:00,56.0,52.0,30.05,NNE,25,0.0,3.0,86,0.00,,,0.00,,
<br>
2010-09-27 00:17:00,56.0,52.0,30.05,NNE,25,0.0,3.0,86,0.00,,,0.00,,
<br>
2010-09-27 00:28:00,56.0,52.0,30.04,NNE,30,2.0,5.0,85,0.00,,,0.00,,
<br>
...

Now you just have to parse the string output to get the information you want.

If you would rather read from the URL and save it to a file instead of loading it as a string variable, you can use the function URLWRITE.

gnovice
CDF parsing can be handled by Matlab: http://www.mathworks.com/help/techdoc/ref/netcdf.html
rwong
@rwong, care to elaborate please? I never heard of netcdf before
Elpezmuerto
+1: Answer is correct. But what a terrible choice of function names on Mathworks' part!
Oli Charlesworth
@Oli Charlesworth: I assume you're referring to URLWRITE, and I would have to agree. Usually functions that have "read" and "write" in their names would be expected to perform complementary actions, like reading *from* a file and writing *to* a file. Since URLWRITE actually reads *then* writes, I think they should rename it to something like URLSAVE. In fact, I think I'll go to the documentation page and suggest it right now! ;)
gnovice
@gnovice: Exactly that.
Oli Charlesworth
@gnoivce, I agree URLSAVE is much better
Elpezmuerto
@Elpezmuerto: Sorry, NetCDF and CDF are totally different formats. My apologies. The MATLAB documentation for CDF is http://www.mathworks.com/help/techdoc/ref/cdflib.html
rwong
A: 

Not sure if this still works, but it is similar:

http://blogs.mathworks.com/videos/2008/12/24/matlab-example-don%E2%80%99t-reinvent-the-thermometer/

MatlabDoug