Call a function that is not on the Matlab path WITHOUT ADDING THAT PATH

后端 未结 5 1557
一生所求
一生所求 2020-12-09 10:36

I have been searching an entire afternoon and have found no solution to call in matlab a function by specifying its path and not adding its directory to the path.

Th

5条回答
  •  情话喂你
    2020-12-09 11:12

    This is doable, but requires a bit of parsing, and a call to evalin.

    I added (many years ago!) a function to the MATLAB Central File Exchange called externalFcn

    http://www.mathworks.com/matlabcentral/fileexchange/4361-externalfcn

    that manages calls to off-path functions. For instance, I have a function called offpathFcn that simply returns a structure with a success message, and the value of an input. Storing that function off my MATLAB path, I can call it using:

    externalfcn('out = C:\MFILES_OffPath\offpathFcn(''this is a test'')');
    

    This returns:

    out = 
        success: 1
        input: 'this is a test'
    

    (Note that my implementation is limited, and improvable; you have to include an output with an equal sign for this to work. But it should show you how to achieve what you want.)

    (MathWorks application engineer)

提交回复
热议问题