This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

matPutVariable (C and Fortran)

Array to MAT-file

C Syntax

#include "mat.h"
int matPutVariable(MATFile *mfp, const char *name, const mxArray 

Fortran Syntax

integer*4 matPutVariable(mfp, name, pm)
mwPointer mfp, pm
character*(*) name



Pointer to MAT-file information


Name of mxArray to put into MAT-file


mxArray pointer


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


This routine puts an mxArray into a MAT-file.

matPutVariable 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.


See the following examples in matlabroot/extern/examples/eng_mat.

Introduced before R2006a

Was this topic helpful?