Main Content

matPutVariableAsGlobal (C and Fortran)

Array to MAT-file as originating from global workspace

C Syntax

#include "mat.h"
int matPutVariableAsGlobal(MATFile *mfp, const char *name, const mxArray *pm);

Fortran Syntax

#include "mat.h"
integer*4 matPutVariableAsGlobal(mfp, name, pm)
mwPointer mfp, pm
character*(*) name

Arguments

mfp

Pointer to MAT-file information

name

Name of mxArray to put into MAT-file

pm

mxArray pointer

Returns

0 if successful and nonzero if an error occurs. In C, use feof and ferror from the Standard C Library with matGetFp to determine status.

Description

This routine puts an mxArray into a MAT-file. matPutVariableAsGlobal is like matPutVariable, except that MATLAB® software loads the array into the global workspace and sets a reference to it in the local workspace. If you write to a MATLAB 4 format file, matPutVariableAsGlobal does not load it as global and has the same effect as matPutVariable.

matPutVariableAsGlobal writes mxArray pm to the MAT-file mfp. If the mxArray does not exist in the MAT-file, the function appends it to the end. If an mxArray with the same name exists in the file, the function replaces the existing mxArray with the new mxArray by rewriting the file.

Do not use MATLAB function names for variable names. Common variable names that conflict with function names include i, j, mode, char, size, or path. To determine whether a particular name is associated with a MATLAB function, use the which function.

The size of the new mxArray can be different from the existing mxArray.

Examples

See these examples in matlabroot/extern/examples/eng_mat:

Version History

Introduced before R2006a