| Data Acquisition Toolbox | Search  Help Desk |
| obj2code | Examples |
Convert device object, channels, or lines to MATLAB code and save to disk.
Syntax
obj2code(obj, 'file');
obj2code(obj, 'file', syntax);
obj2code(obj, 'file', 'all');
obj2code(obj, 'file', syntax, 'all');
Arguments
Description
obj2code(obj, 'file') converts obj to the equivalent MATLAB code using the set syntax and saves the code to file. By default, only those properties that are not set to their default values are written to file.
obj2code(obj, 'file', 'all') converts obj to the equivalent MATLAB code using the set syntax and saves the code to file. 'all' specifies that all properties are written to file.
obj2code(obj, 'file', syntax) converts obj to the equivalent MATLAB code using syntax and saves the code to file. The values for syntax can be 'set', 'dot', or 'named'. 'set' uses the set syntax, 'dot' uses subscripted assignment, 'named' uses named referencing (if defined).
obj2code(obj, 'file', syntax, 'all') converts obj to the equivalent MATLAB code using syntax and saves the code to file. The values for syntax can be 'set', 'dot', or 'named'. 'set' uses the set syntax, 'dot' uses subscripted assignment, and 'named' uses named referencing (if defined). 'all' specifies that all properties are written to file.
Note:
UserData is not empty or if any of the action properties are set to a cell array of values, then the data stored in those properties is written to a MAT-file when the object is converted and saved. The MAT-file has the same name as the M-file containing the object code (see the example below).
Example
Suppose you create the analog input objectai for a sound card, add two channels, and set values for several properties.
The following command writes MATLAB code to the filesai = analoginput('winsound');addchannel(ai, 1:2);set(ai, 'Tag', 'myai', 'TriggerRepeat', 4);set(ai, 'StartAction', {'test', 2, magic(10)});
myai.m and myai.mat
obj2code(ai, 'myai.m', 'dot');
myai.m contains code which recreates the analog input code shown above using subscripted assignment for all properties that have their default values changed. Since StartAction is set to a cell array of values, this property appears in myai.m as
ai.StartAction = startaction
myai.mat as
startaction = {'test', 2, magic(10)});
ai and assign the device object to a new variable ai_new
ai_new = myaiThe associated MAT-file,
myai.mat, is automatically loaded.