MATLAB: How to pass Perl variables when starting MATLAB with the -r option and a MATLAB function

MATLABperlscriptvariable

I would like to know how to pass Perl variables when starting MATLAB with the -r option and a MATLAB function.

Best Answer

This has been incorporated into the Release 2007a documentation (R2007a). For previous product releases, read below:
Consider you have a MATLAB function test, which takes in one input variable:
function test(x)
plot(1:x)
To start MATLAB from the command prompt, with the function TEST, you use the following command:
matlab -r test(10)
On some platforms, you may need to use double quotes when specifying the function:
matlab -r "test(10)"
This command will start a session of MATLAB and call the function TEST with the input argument 10. Now, consider a scenario where you want to pass a Perl variable as the input parameter instead of the constant value 10. This can be done as follows:
1. Create a Perl Script as follows:
#!/usr/local/bin/perl
$val = 10;
system('matlab -r "test(' . ${val} . ')"');
2. Invoke the Perl Script at the command prompt using a Perl interpreter.