in reply to Re^6: Write Matlab binary MAT-files from Perl (repeat)
in thread Write Matlab binary MAT-files from Perl

Hi tye,
I'm sorry, but it didn't work...

Just to make sure I understood correctly:
I changed the print line from this:
print ($h pack ('l5Z*d*', $type, $m, $n, $imag, $len, $name, @a));
to this:
print ($h pack ('l5Z*'.('Z*'x@s), $type, $m, $n, $imag, $len, $name, @a));

and from the main routine called:
mat4_write ('foo', 3, 1, ('aaa','bbb','ccc'), *MAT);

If you have another idea I would love to try it.
If not, I will give it up and save string arrays as their ascii numbers representations and convert back to strings inside matlab...

Thanks and good night,
Koby

p.s: Does Perl has a built-in function that converts a string to an array of its ascii numbers representation?
i.e.: 'ABC' -> (65,66,67)

Replies are listed 'Best First'.
Re^8: Write Matlab binary MAT-files from Perl (repeat)
by Anonymous Monk on Jul 26, 2014 at 00:36 UTC

    What's your perl version? Try this perhaps:

    print $h pack 'l4 l/Z (Z*)*', $type, $m, $n, $imag, $name, @a;
    Re: ascii string to characters—that's simple: my @arr = unpack 'C*', $x;

      Re: ascii string to characters—that's simple: my @arr = unpack 'C*', $x;

      Not if its packed with 'Z*'.

      Plus: Your '(Z*)*' is no substitute for 'd*'. Remember the OP said that d* worked for arrays of less than 10 values.

      Tye called it above with binmode; your addition is unnecessary and wrong.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Thank you both very much for your comments!

        Tye,
        my Perl version is:
        perl 5, version 12, subversion 2 (v5.12.2) built for MSWin32-x64-multi-thread

        The second format you gave me didn't work either...
        It creates a file matlab refuses to load.
        Here is the comparison between this file and the expected one (created by matlab for reference):
        http://srv1.jpg.co.il/10/53d36c18b62cc.jpg

        BrowserUK,
        My strings are "simple" ones (not packed with 'Z*') and the command Tye wrote worked in converting the string to array of ascii numbers.

        Re: Tye called it above with binmode; your addition is unnecessary and wrong.

        I don't understand what you mean... How should I change the format to save the strings in the format matlab needs them...?

        Thanks,
        Koby

Re^8: Write Matlab binary MAT-files from Perl (repeat)
by Anonymous Monk on Jul 25, 2014 at 23:44 UTC

    Forgot to mention that the created file was loaded correctly to Matlab, but the matrix has 3 zeros instead of the 3 desired strings.

    Thanks,
    Koby

      In case this helps, here's the binary comparison between the file the Perl script created (on the left) and the file by matlab as a reference (on the right):
      http://srv2.jpg.co.il/8/53d2ed38850fb.jpg

      I'm going to sleep now,
      it's really late here :)
      Will return in the morning.

      Thanks tye for all your help!
      Koby