MATLAB DATABASE TOOLBOX RELEASE NOTES Guida Utente Pagina 364

  • Scaricare
  • Aggiungi ai miei manuali
  • Stampa
  • Pagina
    / 684
  • Indice
  • SEGNALIBRI
  • Valutato. / 5. Basato su recensioni clienti
Vedere la pagina 363
6 Using Database Toolbox Functions
6-22
Exporting Multiple Records from the MATLAB Workspace
This example does the following:
1
Imports monthly sales figures for all products from the dbtoolboxdemo data source
into the MATLAB workspace.
2
Computes total sales for each month.
3
Exports the totals to a new table.
You use the following Database Toolbox functions:
fastinsert
setdbprefs
For details about these functions, see matlab\toolbox\database\dbdemos
\dbinsert2demo.m.
1
Ensure that the dbtoolboxdemo data source is writable, that is, not read only.
2
Use the database function to connect to the data source, assigning the returned
connection object as conn. Pass the following arguments to this function:
dbtoolboxdemo, the name of the data source
username and password, which are passed as empty strings because no user
name or password is required to access the database
conn = database('dbtoolboxdemo', '', '');
Alternatively, you can use the native ODBC interface for an ODBC connection. For
details, see database.
3
Use the setdbprefs function to specify preferences for the retrieved data. Set the
data return format to numeric and specify that NULL values read from the database
are converted to 0 in the MATLAB workspace.
setdbprefs...
({'NullNumberRead';'DataReturnFormat'},{'0';'numeric'})
When you specify DataReturnFormat as numeric, the value for NullNumberRead
must also be numeric.
4
Import data from the salesVolume table.
curs = exec(conn, 'select * from salesVolume');
Vedere la pagina 363
1 2 ... 359 360 361 362 363 364 365 366 367 368 369 ... 683 684

Commenti su questo manuale

Nessun commento