在C程序中调用MATLAB函数

时间:2018-10-02 02:52:22

标签: c visual-c++

我有一个如下所示的MATLAB函数。

function strReturnAlpha = NumberToAlphabet(num)
%This function gets input as numbers
% and disp[lays the corresponding alphabet
Alphabet=char('abcdefghijklmnopqrstuvwxyz');
if(num < 1 || num > 26)
    strReturnAlpha=strcat('There is no alphabet associated with ',{' 
'},num2str(num));
else
   strReturnAlpha=strcat('The alphabet is ',{' '},Alphabet(num));
end

我生成了lib文件。

我正在尝试从Vc ++程序调用MATLAB函数

C ++函数:

if (mclInitializeApplication(NULL, 0) == false) 
{
    AfxMessageBox(_T("Could not initialize the application properly."));
    return;
}
NumberToAlphabetInitialize();

const mwSize dims[] = { 1,1 };
int *start_of_pr;
int data[] = { 1 };
size_t bytes_to_copy= sizeof(data);

mxArray *mx_a = mxCreateNumericArray(2, dims, mxINT16_CLASS,  mxREAL);

start_of_pr =(int *) mxGetData(mx_a);

start_of_pr[0] = 1;

char str[30];
size_t buflen=30;
mxArray*  output_buf;
output_buf =(mxArray *) mxCalloc(buflen, sizeof(char));

mlxNumberToAlphabet(1, &output_buf, 1, &mx_a);

int len= (mxGetM(output_buf) * mxGetN(output_buf) + 1);
CString sstr;
mxGetString(output_buf,str, sizeof(output_buf));

sstr=str;
AfxMessageBox(sstr);
mxDestroyArray(mx_a);
mxFree(output_buf);

NumberToAlphabetTerminate();
mclTerminateApplication();

您能帮我在C ++程序中与上述MATLAB函数交互吗?

0 个答案:

没有答案