native2unicode

Converts bytes in a given character encoding to a MATLAB character vector.

Category: Language Fundamentals > Data Types

Syntax

str = native2unicode(bytes)

Interprets bytes in the default encoding.

str = native2unicode(bytes, charset)

Interprets bytes using the named encoding.

Description

Text read from files or the network often arrives as raw bytes. native2unicode decodes those bytes according to an encoding, so multi-byte sequences become single characters. In UTF-8, for example, the two bytes 195 169 are one character, the letter e with an acute accent (code 233).

The inverse operation is unicode2native.

Input arguments

bytes
Numeric vector (for example uint8) or char vector holding encoded bytes.
charset
Encoding name such as 'UTF-8' or 'ISO-8859-1'.

Output arguments

str
Char row vector with the decoded text.

Example

native2unicode(uint8([72 101 108 108 111]))
double(native2unicode(uint8([195 169]), 'UTF-8'))
Output
ans = 'Hello'
ans = 233

The second line shows the code point of the decoded character.

See also

unicode2native char double string