3

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.

sebhofer
  • 2,741
  • 18
  • 25
  • Could you perhaps describe the MAT format for those of us unfamiliar with it? – Mr.Wizard Aug 02 '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 03 '12 at 08:29

1 Answers1

1

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.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
  • 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 07 '12 at 11:37