batch file - Call a function by an external application without opening a new instance of Matlab -
is there way call matlab functions outside, in particular windows cmd
(but linux terminal, lua-scripts, etc...), without opening new instance of matlab each time?
for example in cmd
:
matlab -sd mycurrentdirectory -r "function(parameters)" -nodesktop -nosplash -nojvm
opens new instance of matlab relatively fast , executes function. opening , closing of reduced matlab prompt takes 2 seconds (without computations) - hence 4000 executions more 2 hours. i'd avoid this, called function located in same workspace. can done in same instance always?
i did research , found possibility of matlab com automation server, seems quite complicated me , don't see essential steps make work case. advices that?
i'm not familiar c/c++/c#
i'm thinking use of python
(but in worst case).
based on not-working, thought, idea of @ilya kobelevskiy here final workaround:
function pipeconnection(numiterations,inputfile) i=1:numiterations while(exist('inputfile','file')) load inputfile; % read inputfile -> inputdata output = myfunction(inputdata); delete('inputfile'); end % write output file % call external application process output data % generate new inputfile end;
another convenient solution compile executable of matlab function:
mcc -m myfunction
run .exe
-file using cmd
:
cd mycurrentdirectory && myfunction.exe parameter1 parameter2
be aware parameters passed strings , original .m
-file needs adjusted considering that.
further remarks:
- i guess matlab still needs installed on system, though not necessary run it.
- i don't know how far method limited respectively complexity of underlying function.
- the speed-up compared initial apporach given in question relatively small
Comments
Post a Comment