Main Content

obj2mfile

Convert video input objects to MATLAB code

Description

obj2mfile(obj,filename) converts the video input object obj into a MATLAB® code file with the name specified by filename. The file contains the MATLAB code required to restore the object and set its properties. obj can be a single video input object or an array of objects.

The obj2mfile function simplifies the process of restoring an object with specific property settings. obj2mfile also creates and configures the video source object associated with the video input object.

If the UserData property of the object is set, or if any of the callback properties is set to a cell array or to a function handle, obj2mfile writes the data stored in those properties to a MAT-file. obj2mfile gives the MAT-file the same name as the M-file, but uses the .mat filename extension. obj2mfile creates the MAT-file in the same folder as the M-file.

Note

obj2mfile does not store the values of read-only properties. For example, if an object is saved with a Logging property set to 'on', the object is restored with a Logging property set to 'off' (the default value). Use the propinfo function to determine if a property is read-only.

obj2mfile(obj,filename,syntax) converts obj to the equivalent MATLAB code where the syntax argument specifies how to assign values to properties when restoring the object.

obj2mfile(___,mode) converts obj to the equivalent MATLAB code where mode specifies which properties are configured.

obj2mfile(___,reuse) converts obj to the equivalent MATLAB code where the reuse argument specifies whether restoration searches for a reusable video input object or creates a new one.

example

Examples

collapse all

Create a video input object.

 vidobj = videoinput('winvideo', 1, 'RGB24_640x480');

Configure several properties of the video input object.

vidobj.FramesPerTrigger = 100;
vidobj.FrameGrabInterval = 2;
vidobj.Tag = 'CAM1';

Retrieve the selected video source object associated with the video input object.

src = getselectedsource(vidobj);

Configure the properties of the video source object.

src.Contrast = 85;
src.Saturation = 125;

Save the video input object code.

obj2mfile(vidobj,'myvidobj.m','set','modified');

Delete the object and clear it from the workspace.

delete(vidobj);
clear vidobj;

Execute the MATLAB file to restore the object. Note that restoration also creates and configures the associated video source object.

vidObj = myvidobj;

Input Arguments

collapse all

Video input object, specified as a videoinput. obj can be a single video input object or an array of objects. This is the object that you can restore later by running the script created by this function.

Data Types: object

Filename in which to store MATLAB code, specified as a character vector or string. If filename does not specify an extension or if it has an extension other than the MATLAB file extension (.m), obj2mfile appends .m to the end of filename. To restore obj, execute the MATLAB file by calling filename.

Example: 'myvidobj.m'

Data Types: char | string

Property assignment syntax, specified as 'set' or 'dot', according to the following table.

Argument Value

Description

'set'

obj2mfile uses the set function when specifying property values.

'dot'

obj2mfile uses subscripted assignment (dot notation) when specifying property values.

Data Types: char | string

Writable properties set in the MATLAB file code, specified as 'modified' or 'all', according to the following table.

Character Vector

Description

'modified' (default)

Configure only writable properties that are not set to their default values.

'all'

Configure all writable properties. Restoration does not set the values of read-only properties.

Data Types: char | string

Update or create new object when restoring, specified as 'reuse' or 'create', according to the following table.

Argument value

Description

'reuse' (default)

Find and modify an existing object when restoring, if the existing object is associated with the same adaptor and the values of the DeviceID, VideoFormat, and Tag properties match the object being restored. If no matching object is found, restoring creates a new object.

'create'

Create a new object when restoring, regardless of whether there are reusable objects.

Data Types: char | string

Version History

Introduced before R2006a