通过调用外部应用程序功能,而无需打开Matlab的新实例 [英] Call a function by an external application without opening a new instance of Matlab
问题描述
有没有办法由Windows调用Matlab的功能从外部,特别是 CMD
(同时也是Linux终端,LUA的脚本,等...),不必每次都打开Matlab的一个新的实例?
Is there a way to call Matlab functions from outside, in particular by the Windows cmd
(but also the Linux terminal, LUA-scripts, etc...), WITHOUT opening a new instance of Matlab each time?
例如 CMD
:
matlab -sd myCurrentDirectory -r "function(parameters)" -nodesktop -nosplash -nojvm
打开Matlab的一个新实例比较快和执行我的功能。这降低了MATLAB提示开启和关闭时间约2秒(不计算) - 因此4000执行超过2小时。我想避免这种情况,作为被叫功能总是位于相同的工作空间。可它总是相同的情况下怎么办?
opens a new instance of Matlab relatively fast and executes my function. Opening and closing of this reduced matlab prompt takes about 2 seconds (without computations) - hence for 4000 executions more than 2 hours. I'd like to avoid this, as the called function is always located in the same workspace. Can it be done in the same instance always?
我已经做了一些研究,发现的 MATLAB COM自动化服务器,但它似乎很复杂,我,我没有看到必要的步骤,使之成为我的情况下工作。对于任何意见?
I already did some research and found the possibility of the MATLAB COM Automation Server, but it seems quite complicated to me and I don't see the essential steps to make it work for my case. Any advices for that?
我不熟悉的 C / C ++ / C#
,但我想使用蟒蛇
的(但只是在最坏的情况下)。
I'm not familiar with c/c++/c#
but I'm thinking about the use of python
(but just in the worst case).
推荐答案
根据对不工作的,而是经过深思熟虑,@Ilya Kobelevskiy的想法在这里的最终解决方法:
Based on the not-working, but well thought, idea of @Ilya Kobelevskiy here the final workaround:
function pipeConnection(numIterations,inputFile)
for i=1:numIterations
while(exist('inputfile','file'))
load inputfile;
% read inputfile -> inputdata
output = myFunction(inputdata);
delete('inputfile');
end
% Write output to file
% Call external application to process output data
% generate new inputfile
end;
另一种方便的解决办法是编制了Matlab函数的可执行文件:
Another convenient solution would be to compile an executable of the Matlab function:
mcc -m myfunction
运行此 .exe文件
-file使用 CMD
:
cd myCurrentDirectory && myfunction.exe parameter1 parameter2
请注意,参数现在作为字符串传递和原 .M
-file需要调整考虑。
Be aware that the parameters are now passed as strings and the original .m
-file needs to be adjusted considering that.
进一步的说明:
- 我猜Matlab的仍然需要在系统上安装,但
这是没有必要运行它。 - 我不知道有多远这个方法只限于的分别为复杂性
底层函数。 - 的高速化相比,在问题中给出的初始apporach是
相对较小
这篇关于通过调用外部应用程序功能,而无需打开Matlab的新实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!