Documentation Center

  • Trial Software
  • Product Updates

Retrieving Image Data Types

This example retrieves images from the dbtoolboxdemo data source using a sample file that parses image data, matlabroot/toolbox/database/vqb/parsebinary.m.

  1. Connect to the dbtoolboxdemo data source.

    conn = database('dbtoolboxdemo', '', '');
    

    Alternatively, you can use the native ODBC interface for an ODBC connection. For details, see database.

  2. Specify cellarray as the data return format preference.

    setdbprefs('DataReturnFormat','cellarray');
    
  3. Import the InvoiceNumber and Receipt columns of data from the Invoice table.

    curs = exec(conn, 'select InvoiceNumber, Receipt from Invoice')
    curs = fetch(curs);
    
  4. View the data you imported.

    curs.Data
    
    ans = 
    
        [  2101]    [1948410x1 int8]
        [  3546]    [2059994x1 int8]
        [ 33116]    [ 487034x1 int8]
        [ 34155]    [2059994x1 int8]
        [ 34267]    [2454554x1 int8]
        [ 37197]    [1926362x1 int8]
        [ 37281]    [2403674x1 int8]
        [ 41011]    [1920474x1 int8]
        [ 61178]    [2378330x1 int8]
        [ 62145]    [ 492314x1 int8]
        [456789]                  []
        [987654]                  []
    

      Note:   Some OTHER data type fields may be empty, indicating that the data could not pass through the JDBC/ODBC bridge.

  5. Assign the image element you want to the variable receipt.

    receipt = curs.Data{1,2};
    
  6. Run parsebinary. This program writes the retrieved data to a file, strips ODBC header information from it, and displays receipt as a bitmap image in a figure window. Ensure that your current folder is writable so that the output of parsebinary can be written to it.

    cd 'I:\MATLABFiles\myfiles
    parsebinary(receipt, 'BMP');
    

    For details about parsebinary, enter help parsebinary or view its file in the MATLAB® Editor/Debugger by entering open parsebinary.

Was this topic helpful?