MEX: no stdout in release

조회 수: 2 (최근 30일)
Zohar
Zohar 2020년 7월 7일
답변: Harsh 2024년 8월 26일
I build my mex file with VS2019. I do my output with
cout << "hi" << endl;
When I build in release version, it outputs fine to matlab's console; in debug build it doesn't.
  댓글 수: 2
Lukas
Lukas 2024년 1월 25일
Same here. Is there any update on this?
Zohar
Zohar 2024년 1월 25일

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

답변 (1개)

Harsh
Harsh 2024년 8월 26일
Hi @Lukas and @Zohar,
It seems you're attempting to print strings from C++ to MATLAB.
Here are a few alternatives you might consider:
  • Use "mexPrintf " Instead of cout: You can replace "cout" with "mexPrintf " to print directly in MATLAB. Here's an example of how to use "mexPrintf":
#include "mex.h"
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
mexPrintf("This prints in MATLAB again!!\n");
}
  • Error Encountered in Visual Studio: On attempting the same, I noticed an issue where, after running the MEX function along with the C++ file, and then trying to rebuild, an error appears in Visual Studio.
Initially, I executed the MEX file in MATLAB. Subsequently, when I attempted to build again in Visual Studio, I encountered the following error:
This error occurs irrespective of whether you are in release or debug mode. Even when executing the MEX file from the release folder, the error persists.
  • Solution: A simple way to resolve this issue is to restart MATLAB. After doing so, the build process is completed successfully.
(As shown here, the build completes successfully even in debug mode.)
I hope this information is helpful. Thank you!

카테고리

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