Database Toolbox Previous page   Next Page

Creating Cell Arrays for Exporting Data from MATLAB

If you use the insert and update functions to export data from MATLAB to a database and need to include data in a cell array, such as column names, use the following techniques.

Enclosing Data in Curly Braces

One way to put data in a cell array is by enclosing the data in curly braces, with rows separated by semicolons, and elements within a row separated by commas.

For example, to identify the column names in an insert function, use curly braces as follows.

You can also insert the data itself using curly braces. For example, to insert A and avgA, and B and avgB, into the Date and Average columns of the Growth table, use the insert function as follows.

Assigning Cell Array Elements

To put data into a cell array element, enclose it in curly braces. For example, if you have one row containing two values you want to export, A and meanA, put them in cell array exdata, which you will export. Type

Alternatively, you can assign values to exdata in one step by typing

To export the data exdata, use the insert function as follows.

Converting a Numeric Matrix to a Cell Array

If you want to export data containing numeric and string values, you need to export it as a cell array. As an example, you will export a cell array, exdata, whose first column already contains the names of the twelve months. You have calculated the total sales figures for each month and the results are in the numeric matrix monthly. To assign the values in monthly to the second column of the cell array exdata, convert the numeric matrix monthly to a cell array exdata using the num2cell. Type

num2cell takes the data in monthly and assigns each row to the second column in the cell array, exdata.


Previous page  Performing Functions on Cell Array Data Function Reference Next page

© 1994-2005 The MathWorks, Inc.