3
$\begingroup$

I'm trying to export a string to a Matlab mat file. Is it possible? The straightforward way

Export["file.mat", {{"1"}}, {{"Data"}}]

with any number of surrounding braces does not work for me, as I get the error message

Export::type: ({"1"}) cannot be exported to the ("MAT")format.

Any clues?

Edit

To make this a little clearer: I'd like to save some matrices and a string to the same MAT file.

$\endgroup$
2
  • $\begingroup$ Could you perhaps describe the MAT format for those of us unfamiliar with it? $\endgroup$
    – Mr.Wizard
    Aug 2, 2012 at 15:43
  • $\begingroup$ @Mr.Wizard Unfortunately I can't. It's a binary fileformat used by Matlab. The Mathematica doc says that the "Data" element can store "numerical or textual data given as a multidimensional array". But I don't know how. $\endgroup$
    – sebhofer
    Aug 3, 2012 at 8:29

1 Answer 1

1
$\begingroup$

I'm afraid Mathematica may not support this natively. In the documentation for .MAT:

Export["file.mat",expr] exports any numeric array to a MAT-file.

Export["file.mat",expr] creates a MAT-file from an array of integers or doubles.

While the documentation claims that:

Import fully supports MAT Level 4 and 5 files.

It makes no such claim for Export, stately only:

Export generates MAT 4 files.


For reference the binary MAT format is described in this PDF file. It says that level 4 MAT files may contain one or more matrices, but each one may only contain a single data type.

$\endgroup$
1
  • $\begingroup$ Thanks for digging that up! It didn't think of looking up the MAT specification for the different versions, I just saw that it is possible to store strings with my version of Matlab. $\endgroup$
    – sebhofer
    Aug 7, 2012 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.