Database Toolbox    

Working with Cell Arrays in MATLAB

When you import data from a database into MATLAB, the data is stored in MATLAB cell arrays. You can then use MATLAB functions to work with the data. This section provides a few simple examples of how to work with cell arrays in MATLAB.

For more information on using cell arrays, see Chapter 13 of Using MATLAB.

Viewing Query Results

How you view query results depends on if you imported the data using the fetch function or if you used the Visual Query Builder.

Importing Data Using the fetch Function

If you import data from a database to MATLAB using the fetch function, MATLAB returns, for example

To view the retrieved data and assign it to the workspace variable A, type

For this example, MATLAB returns

If the query results consist of multiple columns, you can view all the results for a single column using a colon (:). For example, if running a fetch returns data with multiple columns, you view the results of column 2 by typing

MATLAB returns the data in column 2

Importing Data Using the Visual Query Builder

If you use the Visual Query Builder to import data, you assign the workspace variable, in this example A, using the Visual Query Builder and do not have to perform the above steps. Instead, just type the workspace variable name at the MATLAB prompt in the Command Window. For this example, type

MATLAB returns

Viewing Results Shown as a Matrix

If the results do not fit in the limited display space available, MATLAB expresses them as an array. If for example, MATLAB returns these query results.

you can see the data in rows 1, 2, and 4, but the second column in row 3 is expressed as an array because the results are too long to display.

To view the contents of the second column in the third row, type

MATLAB returns


 Performing Driver Functions Retrieving Elements of Query Results