How do I pass Perl variables when starting MATLAB with the -r option and a MATLAB function?
2 次查看(过去 30 天)
显示 更早的评论
I would like to know how to pass Perl variables when starting MATLAB with the -r option and a MATLAB function.
采纳的回答
MathWorks Support Team
2009-6-27
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!