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

2 visualizaciones (últimos 30 días)
I would like to know how to pass Perl variables when starting MATLAB with the -r option and a MATLAB function.

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 27 de Jun. de 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.

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by