This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Convert numeric bytes to Unicode character representation


unicodestr = native2unicode(bytes)
unicodestr = native2unicode(bytes, encoding)


unicodestr = native2unicode(bytes) converts a numeric vector, bytes, from the user default encoding to a Unicode® character representation. native2unicode treats bytes as a vector of 8-bit bytes, and each value must be in the range [0,255]. The output argument unicodestr is a char vector having the same general array shape as bytes.

unicodestr = native2unicode(bytes, encoding) converts bytes to a Unicode representation with the assumption that bytes is in the character encoding scheme specified by the string encoding. encoding must be the empty string ('') or a name or alias for an encoding scheme. Some examples are 'UTF-8', 'latin1', 'US-ASCII', and 'Shift_JIS'. If encoding is unspecified or is the empty string (''), the default encoding scheme is used.

    Note   If bytes is a char vector, it is returned unchanged.


This example begins with a vector of bytes in an unknown character encoding scheme. The user-written function detect_encoding determines the encoding scheme. If successful, it returns the encoding scheme name or alias as a string. If unsuccessful, it throws an error represented by an MException object, ME. The example calls native2unicode to convert the bytes to Unicode representation:

    enc = detect_encoding(bytes);
    str = native2unicode(bytes, enc);
catch ME

Note that the computer must be configured to display text in a language represented by the detected encoding scheme for the output of disp(str) to be correct.

Introduced before R2006a

Was this topic helpful?