Database Toolbox    

Working with Cell Arrays in MATLAB

When you import data from a database into MATLAB, the data is stored as a numeric matrix, a structure, or a MATLAB cell array, depending on the data return format preference you specified using setdbprefs or the Database Toolbox Preferences dialog box.

Once the data is in MATLAB, you can use MATLAB functions to work with it. Because some users are unfamiliar with cell arrays, this section provides a few simple examples of how to work with the cell array data type in MATLAB:

For more information on using cell arrays, see Structures and Cell Arrays in the MATLAB documentation.

Viewing Cell Array Data Returned from a Query

Viewing Query Results

  1. How you view query results depends on if you imported the data using the fetch function or if you used the Visual Query Builder.
  2. MATLAB displays the data in the Command Window, for example

Viewing Results with Multiple Columns

If the query results consist of multiple columns, you can view all the results for a single column using a colon (:). See the example in Exporting Multiple New Records from MATLAB. For example, you view the results of column 2 by typing

or if you used fetch, you can also view it by typing

MATLAB returns the data in column 2, for example

Expanding Results

If the results do not fit in the 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

or if you used fetch, you can also view it by typing

MATLAB returns


  About Objects and Methods for the Database Toolbox Viewing Elements of Cell Array Data