Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


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

share|improve this question
Could you perhaps describe the MAT format for those of us unfamiliar with it? – Mr.Wizard Aug 2 '12 at 15:43
@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. – sebhofer Aug 3 '12 at 8:29
up vote 1 down vote accepted

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.

share|improve this answer
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. – sebhofer Aug 7 '12 at 11:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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