Database Toolbox | ![]() ![]() |
Specifying Preferences for NULLS, Data Format, and Error Handling
Using preferences, you can specify
setdbprefs
, which is the equivalent function for setting preferences. Note that the settings for writing strings and numbers are not relevant for use in the Visual Query Builder, since you cannot export data using the Visual Query Builder. However, you can change the settings in the Preferences dialog box and those settings will be used if you export data using the Database Toolbox functions.
A
is 320 bytes, compared to 2720 bytes when we ran the query using the previous settings for preferences. This is because we changed the Data return format to numeric
, where previously it was set to cellarray
. The numeric
format requires far less memory than the cellarray
format. However, the cellarray
(or structure
) format is required if you want to retrieve data that is not all numeric, such as strings, or if you want to use the Display menu items. If you use the numeric
format to retrieve data that contains strings, the strings are returned as NULL
values, represented by the preference you specified for Read NULL numbers as.
0
s are displayed where previously there were NaN
s to represent NULL
values. Also note that the data is not in brackets since it is a numeric matrix rather than a cell array.
Saving Preferences
Preferences apply to the current MATLAB session. They are not saved with a query. It is a good practice to verify the preference settings before you run a query, especially if it retrieves a large amount of data.
Another way to set preferences is by using the setdbprefs
function. To use the same preferences whenever you run MATLAB, include the setdbprefs
function in your startup
file.
![]() | Saving a Query | Using Retrieved Data in MATLAB | ![]() |