使用OLE从Delphi XE调用带有字符串参数的MATLAB函数

使用OLE从Delphi XE调用带有字符串参数的MATLAB函数,delphi,matlab,delphi-xe,ole,Delphi,Matlab,Delphi Xe,Ole,我试图使用一个对象调用一个MATLAB函数。该函数有两个字符串参数。当我在Matlab2008a中尝试MATLAB代码时,一切正常,但由于某些原因,我无法从Delphi XE获得MATLAB的输入参数。我如何做到这一点 正如您在我的代码中所看到的,我还尝试在工作区中设置变量,这是我可以接受的解决方法 function Matlab_DoIt(const aInput, aOutput: string): string; var vMatlab, vInput: Variant; begi

我试图使用一个对象调用一个MATLAB函数。该函数有两个字符串参数。当我在Matlab2008a中尝试MATLAB代码时,一切正常,但由于某些原因,我无法从Delphi XE获得MATLAB的输入参数。我如何做到这一点

正如您在我的代码中所看到的,我还尝试在工作区中设置变量,这是我可以接受的解决方法

function Matlab_DoIt(const aInput, aOutput: string): string;
var
    vMatlab, vInput: Variant;
begin
    vInput := aInput;
    vMatlab := CreateOleObject('matlab.application');
    vMatlab.visible := 1;
    vMatlab.Execute('cd c:\localdata\LSCT\Matlab');
    // vMatlab.Execute('input=' + aInput); // nothing happens
    // vMatlab.PutCharArray('input', 'base', aInput); // nothing happens
    // vMatlab.PutCharArray('input', 'base', vInput); // bad variable type error
    // vMatlab.PutCharArray('input', 'global', aInput); // nothing happens
    // vMatlab.PutWorkspaceData('input', 'base', aInput); // nothing happens
    // vMatlab.PutWorkspaceData('input', 'base', vInput); // bad variable type error
    // vMatlab.PutWorkspaceData('input', 'global', aInput); // nothing happens
    // vMatlab.Execute(Format('LSCT_tool_run(%s,%s)', [aInput, aOutput])); // nothing happens
    // vMatlab.Execute(Format('LSCT_tool_run(''%s'',''%s'')', [aInput, aOutput])); // nothing happens
    // vMatlab.Execute(Format('LSCT_tool_run("%s","%s")', [aInput, aOutput])); // nothing happens
    vMatlab.Execute('LSCT_tool_run'); // creates the file, but it is empty
end;
MATLAB代码编写一个包含两个参数的txt文件:

function LSCT_tool_run(input_path, output_path)
    diary ([c:\localdata\LSCT\Matlab\MyFile.txt]);
    diary on;
    % fprintf(input); Only when I try to set the input variable.
    fprintf(inpput_path);
    fprintf(output_path);
    diary off;

在咨询了Mathworks之后,发现这是不可能的。 在这方面,2012版将再次可用