2012-07-09 50 views
0

我正在嘗試使用OLE對象從Delphi XE調用MATLAB函數。該函數有兩個字符串參數。當我嘗試使用MATLAB(2008a)本身的MATLAB代碼時,一切正常,但出於某種原因,我無法從Delphi XE獲得MATLAB的輸入參數。我如何實現這一目標?使用OLE從德爾福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; 

回答

0

與Mathworks公司協商後,事實證明這是不可能的。 2012年版將在這方面再次使用。