heinst
heinst

Reputation: 8786

Read API Into different cells Matlab

I am using an API (link for sample data can be found HERE) The way I have it now, using urlread, it reads all that data into one cell. How do I make it read into multiple cells? The ultimate goal is to extract the location_name, so if you could help me with that too thatd be great!

Upvotes: 0

Views: 164

Answers (1)

Chris Taylor
Chris Taylor

Reputation: 47392

The sample data is provided as JSON, so you want a JSON parser, for example this one.

You use it like this:

>> url      = 'http://www3.septa.org/hackathon/locations/get_locations.php?lon=-75.1903105&lat=39.9601978&type=rail_stations&radius=5';
>> contents = urlread(url);
>> data     = parse_json(contents);
>> data     = data{1};        # For some reason it returns a cell array with one element...
>> data{1}
ans = 
      location_id: 90004
    location_name: '30th Street Station'
     location_lat: '39.9566667'
     location_lon: '-75.1816667'
         distance: '0.5184'
    location_type: 'rail_stations'
    location_data: [1x1 struct]

Upvotes: 2

Related Questions