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 script file in a specified directory, along with a wrapper script, and invokes the Matlab executeable with this wrapper file as input, capturing everything the Matlab program prints to a result string.

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 script file in a specified directory, along with a wrapper script, and invokes the Matlab executeable with this wrapper file as input, capturing everything the Matlab program prints to a result string. 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. If this name refers to an existing file and the $code argument is undefined or an empty string, then the existing file will be executed. The output is stored in the object. Returns true if successful, false otherwise.

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.

wrapper_fn
$wrapper_fn = $matlab->wrapper_fn
$wrapper_fn = $matlab->wrapper_fn($wrapper_fn)

Get or set the file name to use for the wrapper script.

script_fn
$script_fn = $matlab->script_fn
$script_fn = $matlab->script_fn($script_fn)

Get or set the file name to use for the script file.

output_fn
$output_fn = $matlab->output_fn
$output_fn = $matlab->output_fn($output_fn)

Get or set the file name to use for the output file.

remove_files
$matlab->remove_files

Removes the wrapper script, script file and output file from the most recent unsuccessful execute. They are removed automatically for a successful execute. The script file is only removed if it was created during the most recent execute.

COPYRIGHT

Copyright (c) 2002, 2007 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