Hi,
Is it possible to call matlab functions from C S functions? I would need to call fzero and I do not wish to create another C function with the algorithm.
Thanks. Remus.

 採用された回答

Kaustubha Govind
Kaustubha Govind 2012 年 7 月 16 日

1 投票

You can use mexCallMATLAB, but will need to create/destroy mxArrays as needed.

3 件のコメント

Remus Mihail Prunescu
Remus Mihail Prunescu 2012 年 7 月 16 日
Hi. Thanks for your answer. I need to fix some data types in order to call mexCallMATLAB. I get some errors at the moment. Please help :)
My X_A_T, X_B_T and X_C_T are real_T type. So I need to make an mxArray out of it.
mwSize dims[] = {1,3}; // 1x3 array
mxArray *prhs = NULL;
mxArray *lhs[1];
prhs = mxCreateNumericArray(2, dims, mxDOUBLE_CLASS, mxREAL);
prhs[0] = X_A_T; // error C2036: 'mxArray *' : unknown size
// error C2440: '=' : cannot convert from 'real_T' to 'mxArray'
prhs[1] = X_B_T;
prhs[2] = X_C_T;
mexCallMATLAB(1, lhs, 3, &prhs, 'compute_lt_pH');
Q: How do you convert from real_T to mxArray?
Kaustubha Govind
Kaustubha Govind 2012 年 7 月 16 日
Please run the following command to see an example of how you can the copy the data from your real_T arrays into mxArrays:
edit([matlabroot '/extern/examples/refbook/arrayFillGetPr.c']);
Remus Mihail Prunescu
Remus Mihail Prunescu 2012 年 7 月 17 日
It works! Here's an example for a one input, one output matlab function:
mxArray *in[1];
mxArray *out[1];
double *pointer;
in[0] = mxCreateNumericMatrix(3, 1, mxDOUBLE_CLASS, mxREAL);
pointer = mxGetPr(in[0]);
pointer[0] = A_T;
pointer[1] = B_T;
pointer[2] = C_T;
mexCallMATLAB(1, out, 1, in, "myMatlabFun");
pointer = mxGetPr(out[0]);
return *pointer;

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeExternal Language Interfaces についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by