views:

64

answers:

1

Is there a way to return a perl array to MATLAB? Or do I just have to return a string and parse it? I'm using a call from MATLAB to a perl script to interface with a MySQL database. After I get the results of a query, I want to pass it back to MATLAB.

EDIT: I'm using a modified version of perl.m to call the perl script. It calls the version of perl with DBI I installed, rather than the copy that comes with MATLAB.

I changed line 65 of perl.m from

perlCmd = fullfile(matlabroot, 'sys\perl\win32\bin\');

to

perlCmd = 'C:\Perl64\';
+1  A: 

how are you calling your perl script? if you are just doing a system call, then you can only return string output.

you could look into wrapping your call in a mex file, or writing .mat files from your perl, but i suspect string parsing may be easier, especially for small arrays

EDIT

think what i did once in a similar situation (had to transfer data into matlab) was to generate an .m file that creates a matlab matrix, i.e.

array = [
          1, 2, 3;
          4, 5, 6;
         ];

and save to disk. when the program was finished i simply called the m-file to get the data into my workspace

second
I have very little experience with perl, and much more experience with MATLAB, so I'd rather do the bulk of my programming in the environment I'm familiar with.
Doresoom
how large (ish) arrays are we talking about? is going via strings infeasible?
second
My query returns could be up to several thousand data points. I don't think it should be a problem, but I haven't looked into performance yet.
Doresoom
I love it! Using Perl to write an .m file. +1 for creativity. How does this work performance-wise though? Is it going to be faster than reading a .csv file?
Doresoom