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

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

 Accepted 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.

1 Comment

Ucs-2 is not one of the supported encodings and will produce a warning message.
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.

Sign in to comment.

More Answers (0)

Categories

Products

Release

No release entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!