passing unicode string from C mex function to Matlab
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello, I need to send a unicode string from my C mex function to Matlab. At the moment, I try to use mxCreateString to create the variable to return, but unfortunately, I do not get the correct string in Matlab. The string in my C mex function is UTF8 encoded. As far as I can see, the mxCreateString takes a char* only. Does this mean, that mxCreateString can not handle unicode strings? Is there any other way to return unicode strings to Matlab?
Am I correct that Matlab itself uses UTF16 to store strings?
Thank you in advance,
Christian
댓글 수: 0
채택된 답변
Friedrich
2013년 4월 9일
편집: Friedrich
2013년 4월 9일
Hi,
at least the doc states that the mxChar type is 2 byte:
What happens when you use mxCreateCharArray together with a mxGetData and a memcopy? Or you use a loop to write the data in and cast accordingly?
mxArry *tmp = mxCreateCharArray(...)
mxChar *charData = (mxChar *)mxGetData(tmp);
for(j=0; j < nelem_tmp; j++) {
charData[j] = (mxChar)Your_string[j]
}
댓글 수: 2
Jan
2013년 4월 9일
@Christian: Did you try this with non-ASCII values? The conversion from UTF-8 should actually fail tremendously with this method.
추가 답변 (1개)
Jan
2013년 4월 9일
See also:
- http://www.mathworks.com/matlabcentral/answers/3198-convert-matlab-string-to-wchar-in-c-mex-under-windows-and-linux
- http://www.mathworks.com/matlabcentral/newsreader/view_thread/301249
There is the undocumented function mxArrayToString_UTF8.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!