Convert instrument object to MATLAB code





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 .m extension is used.


Syntax of the converted MATLAB code. By default, the set syntax is used. If dot is specified, then the dot notation is used.


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.


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','syntax') converts 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','mode') converts the properties specified by 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','syntax','mode') converts the specified properties to code using the specified syntax.


obj2mfile(obj,'filename','syntax','mode','reuse') check for an existing instrument object, 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.


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')

The following command writes MATLAB code to the files MyGPIB.m and MyGPIB.mat.


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.

ans = 
    'test'    [2]    [10x10 double]

More About

expand all


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.

See Also

Was this topic helpful?