C++ Call Matlab error

조회 수: 12 (최근 30일)
kameranis
kameranis 2020년 12월 31일
댓글: kameranis 2021년 1월 4일
While executing a C++ function called by Matlab I want to report errors back to Matlab. In the C mex API there is mexErrMsgTxt, but I haven't found any corresponding C++ calls. Tried using this helper function
void mxErrorMessage(std::string msg)
{
auto args = factory.createCharArray(msg);
matlabPtr->feval(u"error", args);
}
but I get the following error when I force it to be called
Error using error
Too many output arguments.
Is there a more Matlab appropriate solution that I am missing? Why am I getting this error?
  댓글 수: 2
Rik
Rik 2020년 12월 31일
I have no experience with C++, but the Matlab error sounds like C++ expects the error function to return an output, which it doesn't.
kameranis
kameranis 2020년 12월 31일
That's also how I read it, but looking at the ceval documentation I don't understand how it should be written. The only thing I can imagine is that
matlabPtr->feval(u"error", args);
is an expression and therefore it needs to have a rvalue. This still does not explain how I should be writing this.

댓글을 달려면 로그인하십시오.

답변 (1개)

Rik
Rik 2020년 12월 31일
The way I read the documentation page you linked, you need to do this:
// Call function with no output by using void as the type
matlabPtr->feval<void>(u"error", args);
  댓글 수: 1
kameranis
kameranis 2021년 1월 4일
Thank you for pointing this out. In the past few days I have been experimenting with getting this to work but it seems I am still missing something. I changed the data type of args from auto to a proper type, but it stills refuses to work.
void mxErrorMessage(std::string msg)
{
matlab::data::CharArray args = factory.createCharArray(msg.data());
matlabPtr->feval<void>(u"error", args);
}
The errors from mex can be found here.
It seems to be some sort of type mismatch, but I can't figure it out.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by