Doug’s MATLAB Video Tutorials

March 3rd, 2009

Read data from the web with URLREAD

I am blogging a little early this week because of the holiday. What holiday would that be? Square Root Day- 03/03/09. What makes this a particularly special event is that today’s video is number 144 (12^2) and I recorded it just minutes ago. Posted at 1:44 local time too! This kind of coincidence can not be ignored! When I first thought of this video, I figured it would take three videos to solve the problem. When I actually sat down to read data from the web and interactively filter it, I was happy to see it could be done so quickly and easily. Basically, the procedure is to read data from Many Eyes, then plot that Census data and filter it for city size. We will use URLREAD and TEXTSCAN to bring the data in and then interactive cell mode and plot to filter and visualize it.

7 Responses to “Read data from the web with URLREAD”

  1. Daniel Armyr replied on :

    You are a big nerd.

    But the video was nice. Few lines of code for a large wow-factor.

  2. dhull replied on :

    Daniel,

    Thanks for the kind words about the video.

    Doug

    PS. I prefer the term Geek! :)

  3. Tim Davis replied on :

    URLREAD is great. It’s been a great help. I have a MATLAB interface to the UF Sparse Matrix Collection called UFget, which downloads matrices from the collection into the MATLAB workspace. I used to have a Java component to it, but now I can do it all in M, with URLREAD, and my code is now much simpler (and more robust).

  4. Jim replied on :

    Can you post the code in a text file?

  5. dhull replied on :

    Jim,

    Sorry, I though I did post it. Here it is.

    clear
    clc

    block = urlread(’http://manyeyes.alphaworks.ibm.com/manyeyes/datasets/us-zipcodes-with-city-state-fips-lat/versions/1.txt’);

    %%
    readData = textscan(block, ‘%n %n %s %s %n %n %n %n’, ‘delimiter’, char(9));

    statenum = readData{1};
    zip = readData{2};
    abrev = readData{3};
    city = readData{4};
    lat = readData{5};
    lon = readData{6};
    pop = readData{7};
    percent = readData{8};

    clear readData

    %%

    load usapolygon

    %%
    vi = (pop > 53130.23903);

    plot(uslon, uslat, -lat(vi), lon(vi), ‘.’)

    %%
    city{vi}

    -Doug

  6. Russell replied on :

    This will be really handy as soon as Wolfram|Alpha is up and running!

  7. dhull replied on :

    @Russell,

    I am not sure what you mean, how would they work together?

    Doug

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.

Doug's picture

These postings are the author's and don't necessarily represent the opinions of The MathWorks.