Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

fetch

Retrieve data from STATS.com

Syntax

d = fetch(c)
d = fetch(c,QueryName1,QueryValue1,...,QueryNameN,QueryValueN)

Description

example

d = fetch(c) returns STATS.com data using the STATS.com connection c.

example

d = fetch(c,QueryName1,QueryValue1,...,QueryNameN,QueryValueN) returns STATS.com data using web service query parameters, as specified by one or more name-value pair arguments. The STATS.com web service defines the query parameters. For query parameters, see STATS Developer Center I/O Docs.

Examples

collapse all

Connect to STATS.com using an API key and secret pass code. Specify statistical standings data for basketball teams in the sport league named 'nba' using query parameters.

apikey = 'gkfrq6fabcfehmn2yctrc6j5';
secret = 'aBC5cuBQgc';

sBasketball = statsllc(apikey,secret, ...
    'DataType','stats','LeagueAbbreviation','nba', ...
    'Resource','standings','SportName','basketball', ...
    'VersionNumber','v1');

sBasketball is the STATS.com connection object. For each object property, see statsllc.

Retrieve basketball team data using the STATS.com connection sBasketball.

d = fetch(sBasketball)
d = 

  struct with fields:

            status: 'OK'
       recordCount: 30
    startTimestamp: '2016-04-19T18:37:36.0745302Z'
      endTimestamp: '2016-04-19T18:37:36.9026552Z'
         timeTaken: 0.8281
        apiResults: [1×1 struct]

The query returns a structure d with these fields:

  • status — Web request status ('OK' denotes a successful web request)

  • recordCount — Number of records returned

  • startTimestamp — Start date and time of the web request

  • endTimestamp — End date and time of the web request

  • timeTaken — Amount of time taken for the web request to complete in seconds

  • apiResults — Returned data

Retrieve the basketball team data f for the second conference in the structure array.

f = d.apiResults.league.season.eventType.conferences(2)
f = 

  struct with fields:

    conferenceId: 2
            name: 'Western Conference'
    abbreviation: 'Western'
       divisions: [3×1 struct]

f is a structure with these fields:

  • conferenceId — Conference identifier

  • name — Conference name

  • abbreviation — Conference abbreviation

  • divisions — Divisions in the conference

Retrieve the team identifiers in the first division in the structure array divisions.

f.divisions(1).teams.teamId
ans =

     9

ans =

    12
...

Connect to STATS.com using an API key and secret pass code. Specify statistical standings data for basketball teams in the sport league named 'nba' using query parameters.

apikey = 'gkfrq6fabcfehmn2yctrc6j5';
secret = 'aBC5cuBQgc';

sBasketball = statsllc(apikey,secret, ...
    'DataType','stats','LeagueAbbreviation','nba', ...
    'Resource','standings','SportName','basketball', ...
    'VersionNumber','v1');

sBasketball is the STATS.com connection object. For each object property, see statsllc.

Retrieve basketball team data using the STATS.com connection sBasketball for the 2015 season.

d = fetch(sBasketball,'season','2015')
d = 

  struct with fields:

            status: 'OK'
       recordCount: 30
    startTimestamp: '2016-04-19T18:37:36.0745302Z'
      endTimestamp: '2016-04-19T18:37:36.9026552Z'
         timeTaken: 0.8281
        apiResults: [1×1 struct]

The query returns a structure d with these fields:

  • status — Web request status ('OK' denotes a successful web request)

  • recordCount — Number of records returned

  • startTimestamp — Start date and time of the web request

  • endTimestamp — End date and time of the web request

  • timeTaken — Amount of time taken for the web request to complete in seconds

  • apiResults — Returned data

Retrieve the basketball team data f for the second conference in the structure array.

f = d.apiResults.league.season.eventType.conferences(2)
f = 

  struct with fields:

    conferenceId: 2
            name: 'Western Conference'
    abbreviation: 'Western'
       divisions: [3×1 struct]

f is a structure with these fields:

  • conferenceId — Conference identifier

  • name — Conference name

  • abbreviation — Conference abbreviation

  • divisions — Divisions in the conference

Retrieve the team identifiers in the first division in the structure array divisions.

f.divisions(1).teams.teamId
ans =

     9

ans =

    12
...

Input Arguments

collapse all

STATS.com connection, specified as a statsllc object.

Web service query parameters, specified as one or more pairs of name-value arguments. A QueryName argument is a character vector or string scalar that specifies the name of a query parameter. A QueryValue argument is a character vector or string scalar that specifies the value of the query parameter.

The web service defines name-value pairs that it accepts as part of a request. For valid name-value pairs, see STATS Developer Center I/O Docs. To understand which name-value pairs you have access to, contact STATS.com.

The name-value pairs for this function are different from the name-value pairs specified in statsllc. For details about the differences, contact STATS.com.

Example: 'season','2015' retrieves data for the 2015 season.

Data Types: char | string

Output Arguments

collapse all

STATS.com data, returned as a structure with these fields:

STATS.com Data Structure FieldDescription
status

Web request status ('OK' denotes a successful web request)

recordCount

Number of records returned

startTimestamp

Start date and time of the web request

endTimestamp

End date and time of the web request

timeTaken

Number of seconds to complete the web request

apiResults

Returned data

To retrieve individual or team athletic data, access the field apiResults in the structure. For example, enter:

d.apiResults
ans = 

  struct with fields:

    sportId: 1
       name: 'Basketball'
     league: [1×1 struct]

For more data, continue to access the structure fields that contain further data. For accessing nested structures, see Access Data in Nested Structures (MATLAB).

Introduced in R2016b

Was this topic helpful?