| Database Toolbox | ![]() |
Exporting Multiple New Records from MATLAB
In this example, you import multiple records, manipulate the data in MATLAB, and then export it to a different table in the database. Specifically, you import sales figures for all products, by month, into MATLAB. Then you compute the total sales for each month. Finally, you export the monthly totals to a new table.
You learn to use these Database Toolbox functions:
If you want to see or copy the functions for this example, or if you want to run a similar set of functions, use the M-file matlab\toolbox\database\dbdemos\dbinsert2demo.m:
dbtoolboxdemo according to the directions in Setting Up a Data Source. This data source uses the tutorial database.
tutorial database to be sure it is writable, that is, not read only.
conn. You do not need a username or password to access the dbtoolboxdemo database.
setdbprefs function. Set the data return format to numeric and specify that any NULL value read from the database is to be converted to a 0 in MATLAB.
DataReturnFormat as numeric, the value for NullNumberRead must also be numeric, such as 0, and cannot be a string, such as NaN.
salesVolume table. Type
m and n. In a later step, you use these values to compute the monthly totals. Type
tmp is the sales volume for all products in a given month i, and monthly is the total sales volume of all products for the month i.
For example, when i is 2, row 1 of monthly is the total of all rows in column 2 of curs.Data, where column 2 is the sales volume for January.
salesTotal column of the yearlySales table. The yearlySales table contains no data. Here we assign the array to the variable colnames. Type
yearlySales table by typing
yearlySales table in the tutorial database to be sure the data was imported correctly.
| Replacing Existing Data in a Database MATLAB | Accessing Metadata | ![]() |