NAME
Math::Matlab::Local - Interface to a local Matlab process.
SYNOPSIS
use Math::Matlab::Local;
$matlab = Math::Matlab::Local->new({
cmd => '/usr/local/matlab -nodisplay -nojvm',
root_mwd => '/path/to/matlab/working/directory/'
});
my $code = q/fprintf( 'Hello world!\n' );/;
if ( $matlab->execute($code) ) {
print $matlab->fetch_result;
} else {
print $matlab->err_msg;
}
DESCRIPTION
Math::Matlab::Local implements an interface to a local Matlab executeable. It takes a string containing Matlab code, saves it to a file in a specified directory and invokes the Matlab executeable with this file, capturing everything the Matlab program prints to STDOUT.
Attributes
- cmd
-
A string containing the command used to invoke the Matlab executeable. The default is taken from the package variable $CMD, whose default value is 'matlab -nodisplay -nojvm'
- root_mwd
-
A string containing the absolute path to the root Matlab working directory. All Matlab code is executed in directories which are specified relative to this path. The default is taken from the package variable $ROOT_MWD, whose default value is the current working directory.
METHODS
Public Class Methods
- new
-
$matlab = Math::Matlab::Local->new; $matlab = Math::Matlab::Local->new( { cmd => '/usr/local/matlab -nodisplay -nojvm', root_mwd => '/root/matlab/working/directory/' } )
Constructor: creates an object which can run Matlab programs and return the output. Attributes 'cmd' and 'root_mwd' can be initialized via a hashref argument to new(). Defaults for these values are taken from the package variables $CMD and $ROOT_MWD, respectively.
Public Object Methods
- execute
-
$TorF = $matlab->execute($code) $TorF = $matlab->execute($code, $relative_mwd) $TorF = $matlab->execute($code, $relative_mwd, $filename)
Takes a string containing Matlab code, saves it to a command file in a specified directory and invokes the Matlab executeable with this file as input, capturing everything the Matlab program prints to STDOUT. The optional second argument specifies the Matlab working directory relative to the root Matlab working directory for the object. This is where the command file will be created and Matlab invoked. The optional third argument specifies the filename to use for the command file. The output is stored in the object. Returns true if successful, false otherwise.
- create_cmd_file
-
$filename = $matlab->create_cmd_file($code) $filename = $matlab->create_cmd_file($code, $filename) $filename = $matlab->create_cmd_file($code, $filename, $overwrite)
Saves the given Matlab code to a new command file. If no filename is given, it generates a random unique one. If the filename is given and a file already exists with that name, it will throw an exception, unless the third optional argument is true. In that case it will overwrite the file. It returns the name of the file created.
- cmd
-
$cmd = $matlab->cmd $cmd = $matlab->cmd($cmd)
Get or set the command used to invoke Matlab.
- root_mwd
-
$root_mwd = $matlab->root_mwd $root_mwd = $matlab->root_mwd($root_mwd)
Get or set the root Matlab working directory.
CHANGE HISTORY
10/16/02 - (RZ) Created.
COPYRIGHT
Copyright (c) 2002 PSERC. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
Ray Zimmerman, <rz10@cornell.edu>
SEE ALSO
perl(1), Math::Matlab