0

I would like to know how one could call MATLAB from a Perl script? To be exact, I want to run a *.m file with

a = zeros(10)

from Perl. by the way, I am using Eclipse as an IDE for Perl.

I searched for a while, but could not find a clear answer. Please help!

Royeh
  • 433
  • 5
  • 21
  • 3
    There are several PerlMonks nodes about this: http://www.perlmonks.org/?node_id=642247, http://www.perlmonks.org/?node_id=818233 – Hunter McMillen Jul 27 '15 at 13:48
  • 3
    See also [Running an m-file from command-line](http://stackoverflow.com/questions/6657005/matlab-running-an-m-file-from-command-line), and [Start MATLAB program from Linux system prompt](http://se.mathworks.com/help/matlab/ref/matlablinux.html) – Håkon Hægland Jul 27 '15 at 13:53
  • 1
    or https://metacpan.org/pod/Math::Matlab::Local – clt60 Jul 27 '15 at 16:37
  • @HunterMcMillen Thanks a lot! I found out the solution as you both mentioned in the links and then I am posting it here. – Royeh Jul 28 '15 at 10:02
  • @jm666 Thanks a lot! I found out the solution as you both mentioned in the links and then I am posting it here. – Royeh Jul 28 '15 at 10:02

1 Answers1

1

One could write here an *.m file for Matlab without using Matlab text editor or just comment the following lines till line EOF.

Start to write into 'Call_mfile.m' all lines after print $matlab <<EOF;

open(my $matlab, '>', 'Call_mfile.m');
print $matlab <<EOF;

 close all;
 clear all;
 clc;

% write here your Matlab code
a = zeros(10)

%--------------------------------------------------------------------------
EOF
###########################################################################
# Use this command when you want to update your toolbox
#system('matlab rehash toolboxcache')

# Use this when you want to use Java interface!
# Notice!!
#    This could not then open another files which are called in Call_mfile.m 
#    file. Otherwise use the next command!

#system('matlab -nojvm -r Call_mfile');
system('matlab -r Call_mfile');
Royeh
  • 433
  • 5
  • 21