User`s manual

Examples of MAT-Files
6-13
pa3 = mxCreateString("MATLAB: the language of technical
computing");
if (pa3 == NULL) {
printf("%s : Out of memory on line %d\n",
__FILE__, __LINE__);
printf("Unable to create string mxArray.\n");
return(EXIT_FAILURE);
}
mxSetName(pa3, "LocalString");
status = matPutArray(pmat, pa1);
if (status != 0) {
printf("%s : Error using matPutArray on line %d\n",
__FILE__, __LINE__);
return(EXIT_FAILURE);
}
status = matPutArrayAsGlobal(pmat, pa2);
if (status != 0) {
printf("Error using matPutArrayAsGlobal\n");
return(EXIT_FAILURE);
}
status = matPutArray(pmat, pa3);
if (status != 0) {
printf("%s : Error using matPutArray on line %d\n",
__FILE__, __LINE__);
return(EXIT_FAILURE);
}
/*
* Ooops! we need to copy data before writing the array. (Well,
* ok, this was really intentional.) This demonstrates that
* matPutArray will overwrite an existing array in a MAT-file.
*/
memcpy((void *)(mxGetPr(pa1)), (void *)data, sizeof(data));
status = matPutArray(pmat, pa1);