unicode2native - Convert Unicode characters to numeric bytes
Syntax
bytes = unicode2native(unicodestr)
bytes = unicode2native(unicodestr,
encoding)
Description
bytes = unicode2native(unicodestr) takes a char vector of Unicode characters, unicodestr, converts it to the MATLAB default character
encoding scheme, and returns the bytes as a uint8 vector, bytes. Output vector bytes has the same general array shape as the unicodestr input. You can save the output of unicode2native to a file using the fwrite function.
bytes = unicode2native(unicodestr,
encoding) converts the Unicode characters to 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'. For common
names and aliases, see the Web site http://www.iana.org/assignments/character-sets. If encoding is unspecified or is the
empty string (''), the MATLAB default encoding
scheme is used.
Examples
This example begins with two strings containing Unicode characters.
It assumes that string str1 contains text in a
Western European language and string str2 contains
Japanese text. The example writes both strings into the same file,
using the ISO-8859-1 character encoding scheme for the first string
and the Shift-JIS encoding scheme for the second string. The example
uses unicode2native to convert the two strings
to the appropriate encoding schemes.
fid = fopen('mixed.txt', 'w');
bytes1 = unicode2native(str1, 'ISO-8859-1');
fwrite(fid, bytes1, 'uint8');
bytes2 = unicode2native(str2, 'Shift_JIS');
fwrite(fid, bytes2, 'uint8');
fclose(fid);
See Also
native2unicode
 | undocheckout | | union |  |
Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
Get the Interactive Kit