When I tried to use the C function 'matOpen' to open a mat file with Chinese characters in the C code, I found an unknown error.
조회 수: 9 (최근 30일)
이전 댓글 표시
I am now trying to use MATLAB C API to read mat-file Data. When all the paths I use contain only ASCII characters, everything is normal. But when the path I read contains Chinese characters, the matOpen function will return NULL.
Since the C function 'matOpen' can only receive char type arrays as file paths, I tried to convert the path from wchar_t type (UTF-16) into single-byte characters in different encoding forms (such as UTF-8), and tried again but still can not be used normally. And, I am sure that the operation permissions of the path are completely correct.
In addition, I tried to use the standard function 'fopen' in the C code, and the result was completely normal.
The IDE I use is Visual Studio 2019.
댓글 수: 0
답변 (1개)
Rishav
2024년 4월 17일
Hi Yanming,
In MATLAB R2019b, the MAT-file API has been updated, and as part of these changes, the initialization routine for international character support is not automatically invoked by the API.
As a workaround for this issue, you can use the attached files to manually call this initialization before calling 'matOpen'. To use the attached workaround, make sure to include the 'matlab_i18n_init.h' library and then call the provided "matlab_i18n_init" function before working with 'matOpen', for example:
#include "matlab_i18n_init.h"
if (matlab_i18n_init()!=0) {
printf("Error initializing MATLAB i18.\n");
return;
}
Furthermore, make sure to compile 'matlab_i18n_init.c' and link in the binary.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!