Data Acquisition Toolbox | ![]() ![]() |
Saving and Loading Device Objects
You can save a device object to disk using two possible formats:
For analog input objects, you can also save acquired data, hardware information, and so on to a log file. Refer to Logging Information to Disk for more information.
Saving Device Objects to an M-File
You can save a device object to an M-file using the obj2mfile
function. obj2mfile
provides you with these options:
Read-only property values are not saved. Therefore, read-only properties use their default values when you load the device object into the MATLAB workspace. To determine if a property is read-only, use the propinfo
function or examine the property reference pages.
set
syntax, the dot notation, or named referencing (if defined).If the UserData
property is not empty, or if action properties are set to a cell array of values, then the data stored in these properties is written to a MAT-file when the device object is saved. The MAT-file has the same name as the M-file containing the device object code.
For example, suppose you create the analog input object ai
for a sound card, add two channels to it, and configure several property values.
ai = analoginput('winsound'); addchannel(ai,1:2,{'Temp1';'Temp2'}); time = now; set(ai,'SampleRate',11025,'TriggerRepeat',4) set(ai,'TriggerAction',{'myaction',time}) start(ai)
The following command saves ai
and the modified property values to the M-file myai.m.
Since the TriggerAction
property is set to a cell array of values, its value is automatically written to the MAT-file myai.mat
.
obj2mfile(ai,'myai.m'); Created: d:\v6\myfiles\myai.m Created: d:\v6\myfiles\myai.mat
Use the type
command to display myai.m
at the command line.
Loading the Device Object
To load a device object that was saved as an M-file into the MATLAB workspace, type the name of the M-file at the command line. For example, to load ai
from the M-file myai.m
ai = myai
Note that the read-only properties such as SamplesAcquired
and SamplesAvailable
are restored to their default values.
get(ai,{'SamplesAcquired','SamplesAvailable'}) ans = [0] [0]
When loading ai
into the workspace, the MAT-file myai.mat
is automatically loaded and the TriggerAction
property value is restored.
ai.TriggerAction ans = 'myaction' [7.3071e+005]
![]() | Saving and Loading the Session | Saving Device Objects to a MAT-File | ![]() |