in reply to Write Matlab binary MAT-files from Perl

I saw they differ in 1 additional byte...

And you don't want to share what that byte's value and offset were? Maybe even which file had the extra byte? That information might lead to you getting a much more detailed and/or useful response (at least faster).

I couldn't find a match there for the 'l5Z*d*' format the routine above uses...

That is just 'l' (lower-case L) to be used on 5 arguments, 'Z' to be used on one argument with '*' meaning to just take the length from the argument, and 'd' to be used on each of the remaining arguments ('*').

- tye        

  • Comment on Re: Write Matlab binary MAT-files from Perl (which byte)

Replies are listed 'Best First'.
Re^2: Write Matlab binary MAT-files from Perl (which byte)
by Anonymous Monk on Jul 25, 2014 at 21:10 UTC

    Hi tye,
    Thanks!
    I have no problem sharing the byte's offset, I have nothing to hide :)
    It looks like it's the 9th byte (Byte 8 starting from 0).

    It has the value 0x0D and it is apparently an un-needed extra byte located only on the file created in the Perl script and not in the same vector saved directly from matlab.

    You can see a screenshot below of the comparisong in BeyondCompare:
    (I hope you can see the picture in the link below)

    http://srv2.jpg.co.il/2/53d2c3d4335d0.jpg

    Do you have any idea how to fix that...?

    Thanks,
    Koby

        Thanks tye!
        I saw the link, and tried to read it.
        I admit it was quite intimidating at first, but actually quite simple!
        Thank you very much!
        The script works now!
        You've helped me a lot!

        For others who might find this thread and need this MAT saving routine from Perl,
        below you can see the modified function. Works perfectly now (with binmode activated)!

        Thanks,
        Koby

        sub mat4_write { # Variable name. my $name = shift; # Number of rows. my $m = shift; # Number of columns. my $n = shift; # Matrix elements in column major layout, this is the native # Matlab storage layout for matrices. my @a = splice (@_, 0, $m * $n); # File handle. my $h = shift; # use binnary-mode: binmode($h); # Type flag. my $type = $mat4_type; # No imaginary part. my $imag = 0; # Length of variable name including terminating null character. my $len = length ($name) + 1; # Encode and print matrix. print ($h pack ('l5Z*d*', $type, $m, $n, $imag, $len, $name, @a)); }

        Thanks tye,
        but excuse my ignorence,
        how do I use the binmode...?

        I've attached below the 'mat4_write' code.
        Where should I tell it to use the binmode...?

        Thanks,
        Koby

        sub mat4_write { # Variable name. my $name = shift; # Number of rows. my $m = shift; # Number of columns. my $n = shift; # Matrix elements in column major layout, this is the native # Matlab storage layout for matrices. my @a = splice (@_, 0, $m * $n); # File handle. my $h = shift; # Type flag. my $type = $mat4_type; # No imaginary part. my $imag = 0; # Length of variable name including terminating null character. my $len = length ($name) + 1; # Encode and print matrix. print ($h pack ('l5Z*d*', $type, $m, $n, $imag, $len, $name, @a)); }