| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Database Toolbox |
| Contents | Index |
| Learn more about Database Toolbox |
This example shows how to view information about imported data and close the connection to the database using the following Database Toolbox functions:
For more information on these functions, see matlab\toolbox\database\dbdemos\dbinfodemo.m.
Open the cursor and connection if needed:
conn = database('SampleDB', '', '');
curs = exec(conn, 'select country from customers');
setdbprefs('DataReturnFormat','cellarray');
curs = fetch(curs, 10);
Use rows to return the number of rows in the data set:
numrows = rows(curs)
numrows =
10
Use cols to return the number of columns in the data set:
numcols = cols(curs)
numcols =
1
Use columnnames to return the names of the columns in the data set:
colnames = columnnames(curs) colnames = 'country'
Use width to return the column width, or size of the field, for the specified column number:
colsize = width(curs, 1)
colsize =
15
Use attr to view multiple attributes for a column:
attributes = attr(curs)
attributes =
fieldName: 'country'
typeName: 'VARCHAR'
typeValue: 12
columnWidth: 15
precision: []
scale: []
currency: 'false'
readOnly: 'false'
nullable: 'true'
Message: []
Tip To import multiple columns, include a colnum argument in attr to specify the number of columns whose information you want. |
close(curs)
Continue with the next example. To stop working now and resume working on the next example at a later time, close the connection.
close(conn)
![]() | Importing Data from Databases into the MATLAB Workspace | Exporting Data from the MATLAB Workspace to a New Record in a Database | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |