将阿拉伯字母存储到字符数组matlab中

时间:2017-07-08 12:45:39

标签: arrays matlab arabic

我正在尝试制作一个阿拉伯字母数组,在其上循环并在文本文件中写入字母。问题是matlab无法识别它,它给出了'?'而不是字母。我正在使用matlab 2016a。

% slCharacterEncoding()
fid = fopen('nv.txt', 'w+', 'n', 'UTF-8');
words = ['ا','ل','ل','ه',' ', 'و'];
for i=1:length(words)
    w=words(1,i);
    fprintf(fid,'%s',w);
end
fclose(fid);

enter image description here

奇怪的是,当我从命令输入words数组并从代码中注释它的行时,它可以正常工作。 enter image description here

1 个答案:

答案 0 :(得分:2)

一种解决方法是使用uint16在命令窗口中获取其16位整数值,即

>> words = ['ا','ل','ل','ه',' ', 'و'];
>> uint16(words)

ans =

   1575   1604   1604   1607     32   1608

现在在您的m文件中替换words = char([1575 1604 1604 1607 32 1608]);