obj2mfile
Convert instrument object to MATLAB code
Syntax
obj2mfile(obj,'filename')
obj2mfile(obj,'filename','syntax
')
obj2mfile(obj,'filename','mode
')
obj2mfile(obj,'filename','syntax
','mode
')
obj2mfile(obj,'filename','reuse
')
obj2mfile(obj,'filename','syntax'
,'mode
','reuse
')
Arguments
| An instrument object or an array of instrument objects. |
| The name of the file that the MATLAB® code is written to. You can specify the full
pathname. If an extension is not specified, the
. |
| Syntax of the converted MATLAB code. By default, the |
| Specifies whether all properties are converted to code, or only modified properties are converted to code. |
| Specifies whether existing object is reused or new object is created. |
Description
obj2mfile(obj,'filename')
converts
obj
to the equivalent MATLAB code using the set
syntax and saves the code to
filename
. Only those properties not set to their default
value are saved.
obj2mfile(obj,'filename','
converts syntax
')obj
to the equivalent MATLAB code using the syntax specified by syntax
.
You can specify syntax
to be set
or
dot
. set
uses the set syntax, while
dot
uses the dot notation.
obj2mfile(obj,'filename','
converts the properties specified by mode
')mode
. You can
specify mode
to be all
or
modified
. If mode
is
all
, then all properties are converted to code. If
mode
is modified
, then only those
properties not set to their default value are converted to code.
obj2mfile(obj,'filename','
converts the specified properties to code using the specified syntax.syntax
','mode
')
obj2mfile(obj,'filename','
check for an existing instrument object, reuse
')obj
, before creating
obj
. If reuse
is
reuse
, the object is used if it exists, otherwise the object
is created. If reuse
is create
, the
object is always created. By default, reuse
is
reuse
.
An object will be reused if the existing object has the same constructor arguments
as the object about to be created, and if their Type
and
Tag
property values are the same.
obj2mfile(obj,'filename','
check for an existing instrument object, syntax'
,'mode
','reuse
')obj
, before creating
obj
. If reuse
is
reuse
, the object is used if it exists, otherwise the object
is created. If reuse
is create
, the
object is always created. By default, reuse
is
reuse
.
An object will be reused if the existing object has the same constructor arguments
as the object about to be created, and if their Type
and
Tag
property values are the same.
Examples
Suppose you create the GPIB object g
, and configure several
property values.
g = gpib('ni',0,1); set(g,'Tag','MyGPIB object','EOSMode','read','EOSCharCode','CR') set(g,'UserData',{'test',2,magic(10)})
The following command writes MATLAB code to the files MyGPIB.m
and
MyGPIB.mat
.
obj2mfile(g,'MyGPIB.m','dot')
MyGPIB.m
contains code that recreates the commands shown above
using the dot notation for all properties that have their default values changed.
Because UserData
is set to a cell array of values, this property
appears in MyGPIB.m
as obj1.UserData =
userdata1
.
It is saved in MyGPIB.mat
as userdata = {'test', 2,
magic(10)}
.
To recreate g
in the MATLAB workspace using a new variable, gnew
,
gnew = MyGPIB;
The associated MAT file, MyGPIB.mat
, is automatically run and
UserData
is assigned the appropriate values.
gnew.UserData
ans = 1×3 cell array {'test'} {[2]} {10×10 double}
Tips
You can recreate a saved instrument object by typing the name of the file at the MATLAB Command Window.
If the UserData
property is not empty or if any of the
callback properties are set to a cell array of values or a function handle, then the
data stored in those properties is written to a MAT file when the instrument object
is converted and saved. The MAT file has the same name as the file containing the
instrument object code (see the example below).
Read-only properties are restored with their default values. For example, suppose
an instrument object is saved with a Status
property value of
open
. When the object is recreated,
Status
is set to its default value of
closed
.
Note
To get a list of options you can use on a function, press the Tab key after entering a function on the MATLAB command line. The list expands, and you can scroll to choose a property or value. For information about using this advanced tab completion feature, see Using Tab Completion for Functions.
Version History
Introduced before R2006a