MATLAB DATABASE TOOLBOX RELEASE NOTES Guide de l'utilisateur Page 655

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 684
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 654
setdbprefs
7-225
conn = database('MySQL','username','pwd');
Alternatively, you can use the native ODBC interface for an ODBC connection. For
details, see the database function.
Import data into the MATLAB workspace.
curs = exec(conn,...
'select productnumber,productdescription from producttable');
curs = fetch(curs,3);
curs.Data
ans =
[9] 'Victorian Doll'
[8] 'Train Set'
[7] 'Engine Kit'
Resulting data displays as a cell array.
Change the data return format from cellarray to numeric.
setdbprefs('DataReturnFormat','numeric')
Import data into the MATLAB workspace.
curs = exec(conn,...
'select productnumber,productdescription from producttable');
curs = fetch(curs,3);
curs.Data
ans =
9 NaN
8 NaN
7 NaN
In the database, the values for productDescription are character strings, as seen in
the previous example when DataReturnFormat was set to cellarray. Therefore, the
productDescription values cannot be read when they are imported into the MATLAB
workspace using the numeric format. Therefore, MATLAB treats them as NULL numbers
and assigns them the current value for the NullNumberRead property of NaN.
Change the data return format to structure.
Vue de la page 654
1 2 ... 650 651 652 653 654 655 656 657 658 659 660 ... 683 684

Commentaires sur ces manuels

Pas de commentaire