How do I pass Perl variables when starting MATLAB with the -r option and a MATLAB function?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I would like to know how to pass Perl variables when starting MATLAB with the -r option and a MATLAB function.
Réponse acceptée
MathWorks Support Team
le 27 Juin 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.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur File Operations dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!