How do I pass Perl variables when starting MATLAB with the -r option and a MATLAB function?

5 views (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
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.

More Answers (0)

Categories

Find more on Variables in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!