フィルターのクリア

How to call mexCallMATLAB on a function that has inputs of different types?

4 ビュー (過去 30 日間)
Robert
Robert 2013 年 6 月 20 日
I would like to call the following function from a mex file:
norm(X, 'fro')
X is a double matrix. 'fro' is obviously a character array. How would I construct an input array, such to be able to use mexCallMATLAB, i.e.:
mexCallMATLAB(1, normOutputs, 2, normInputs, "norm")
Since the inputs have different types (mxArray and character array), I'm not sure how to construct an array of pointers to them. Help would be greatly appreciated!

回答 (2 件)

James Tursa
James Tursa 2013 年 6 月 20 日
編集済み: James Tursa 2013 年 6 月 20 日
mxArray *normInputs[2];
mxArray *normOutputs[1];
normInputs[0] = mxCreateDoubleMatrix(2,2,mxREAL); // a double matrix
// code to fill in normInputs[0]
normInputs[1] = mxCreateString("fro");
mexCallMATLAB(1,normOutputs,2,normInputs,"norm");
mxDestroyArray(normInputs[1]);
mxDestroyArray(normInputs[0]);
// use normOutputs[0]
mxDestroyArray(normOutputs[0]);
  5 件のコメント
James Tursa
James Tursa 2013 年 6 月 20 日
編集済み: James Tursa 2013 年 6 月 20 日
Hmmm ... I thought norm always returned an answer. You can try this:
if( normOutputs[0] ) {
mxDestroyArray(normOutputs[0]);
}
Or just remove the mxDestroyArray(normOutputs[0]) line completely and let the garbage collection handle it.
Neither of these answers is satisfactory to me, however, since to my understanding of the mexCallMATLAB call you should get a normOutputs[0] result. Don't know why this would not be the case. Are you sure you haven't already called mxDestroyArray(normOutputs[0]) prior to this line?
Robert
Robert 2013 年 6 月 20 日
編集済み: Robert 2013 年 6 月 20 日
I figured out the problem! I am running this code in a loop, and the problem actually occurred the second time mxDestroyArray(normOutputs[0]) was called. So, if I put this line outside of the loop, the error goes away.

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


Jan
Jan 2013 年 6 月 20 日
編集済み: Jan 2013 年 6 月 20 日
No, the inputs do not have different types and 'fro' is not a char vector, although it looks like it is one. Both variables must be mxArrays to be valid input arguments for mxCallMATLAB. So the 2nd normInput must be an mxArray pointer of the type mxCHAR (as shonw in James' example already):
normInput[1] = mxCreateString('fro');

カテゴリ

Help Center および File ExchangeAdding custom doc についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by