Database Toolbox    
fetch

Import data into MATLAB

Syntax

Description

curs = fetch(curs, RowLimit) imports rows of data from the open SQL cursor curs, up to the specified RowLimit, into the object curs. Data is stored in MATLAB in a cell array, structure, or numeric matrix, based on specifications you made using setdbprefs. It is common practice to assign the object returned by fetch to the variable curs from the open SQL cursor. The next time you run fetch, records are imported starting with the row following RowLimit. If you fetch large amounts of data that cause out of memory or speed problems, use RowLimit to limit how much data is retrieved at once.

curs = fetch(curs) imports rows of data from the open SQL cursor curs, up to the RowLimit specified by set, into the object curs. Data is stored in MATLAB in a cell array, structure, or numeric matrix, based on specifications you made using setdbprefs. It is common practice to assign the object returned by fetch to the variable curs from the open SQL cursor. The next time you run fetch, records are imported starting with the row following RowLimit. If no RowLimit was specified by set, fetch imports all remaining rows of data.

Running fetch returns information about the cursor object. The Data element of the cursor object contains the data returned by fetch. The data types are preserved. After running fetch, display the returned data by typing curs.Data.

Use get to view properties of curs.

Examples

Example 1--Import All Rows of Data

Import all of the data into the cursor object curs.

MATLAB returns

The fetch operation stores the data in a cell array contained in the cursor object field curs.Data. To display data in curs.Data, type

MATLAB returns all of the data, which in this example consists of 1 column and 91 rows, some of which are shown here.

Example 2--Import Specified Number of Rows of Data

Specify the RowLimit argument to retrieve the first 3 rows of data.

MATLAB returns

Display the data by typing

MATLAB returns

Entering the fetch function again returns the second 3 rows of data. Adding the semicolon suppresses display of the results.

Display the data by typing

MATLAB returns

Example 3--Import Numeric Data

Import a column of data that is known to be numeric. Use setdbprefs to specify the format for the retrieved data as numeric.

MATLAB retrieves the data into a numeric matrix.

See Also
attr, cols, columnnames, exec, get, rows, resultset, set, width


  exportedkeys get