| 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:
propinfo function or examine the property reference pages.
set syntax, the dot notation, or named referencing (if defined).
UserData property is not empty, or if a callback property is set to a cell array of values or a function handle, 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,'TriggerFcn',{@mycallback,time}) start(ai)
The following command saves ai and the modified property values to the M-file myai.m. Because the TriggerFcn property is set to a cell array of values, its value is automatically written to the MAT-file 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:
Note that the read-only properties such as SamplesAcquired and SamplesAvailable are restored to their default values.
When loading ai into the workspace, the MAT-file myai.mat is automatically loaded and the TriggerFcn property value is restored.
| Saving and Loading the Session | Saving Device Objects to a MAT-File | ![]() |