Hi guys,
I'm trying to write matlab binary MAT files from Perl.
Does anyone have a working routine/function that does that already?
I guess I'm not the first one trying to do this... but couldn't find a solution on this website or other pages.

I've been trying to follow this thread:
http://mathforum.org/kb/message.jspa?messageID=7738560
which basically works, but only for arrays that are shorter than 9 elements...
Arrays longer than that (in most cases) cannot be loaded correctly into matlab and produce the following error message:

> ??? Error using ==> load > Unable to read MAT-file C:\tools\mat4.mat > > File may be corrupt.

For example:
This works fine:
> mat4_write('foo', 1, 9, (1,2,3,4,5,6,7,8,9), *MAT);
And this does not (generates the error message above when trying to load the file into matlab):
> mat4_write('foo', 1, 10, (1,2,3,4,5,6,7,8,9,10), *MAT);

I saw the mat4_write routine (from the link above) uses the 'pack' function in this way:
print ($h pack ('l5Z*d*', $type, $m, $n, $imag, $len, $name, @a));

I also noticed that the mat file created is very close to the needed format, but not identical...
And by comparing the created file to a similar file created from matlab (with same data, for a reference) I saw they differ in 1 additional byte...

I have never used the 'pack' function, and the help from the link below is hard to follow:
http://perldoc.perl.org/functions/pack.html
I couldn't find a match there for the 'l5Z*d*' format the routine above uses...

Can someone please help me with that...?
Does anyone have a working conversion function?
Please help!

Thanks,
Koby


In reply to Write Matlab binary MAT-files from Perl by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.