MATLAB: How to read an UCS-2 encoded file in MATLAB

encodingfopenleMATLABucs-2ucs2utfutf-16

How it is possible to read an UCS-2 encoded file in MATLAB with the function 'fopen'?

Best Answer

To load an UCS-2 encoded file with fopen, one has to set the encoding parameter of fopen.
This works like the following for the file 'example.txt':
myfid = fopen('example.txt','r', 'ieee-le', 'UCS-2' )
Specifying UCS-2 does not specify how characters beyond 255 are encoded.
The only supported encoding is UTF-8.
UCS-2 is essentially only a character list that is kept fairly synchronized with Unicode, but Unicode gets updated more often. If the difference between UCS-2 and Unicode is important to you then you are likely to be disappointed, as the MATLAB implementation of both is not kept up freshly to date.