Call a function by an external application without opening a new instance of Matlab

后端 未结 4 1371
说谎
说谎 2020-11-28 15:43

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

4条回答
  •  难免孤独
    2020-11-28 16:13

    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;
    

    Another convenient solution would be to compile an executable of the Matlab function:

    mcc -m myfunction
    

    run this .exe-file using cmd:

    cd myCurrentDirectory && myfunction.exe parameter1 parameter2
    

    Be aware that the parameters are now passed as strings and the original .m-file needs to be adjusted considering that.

    further remarks:

    • I guess Matlab still needs to be installed on the system, though it is not necessary to run it.
    • I don't know how far this method is limited respectively the complexity of the underlying function.
    • The speed-up compared to the initial apporach given in the question is relatively small

提交回复
热议问题