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.
14 次查看(过去 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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!