沙洛姆
我正在尝试使用matlab中的希伯来字符串。但是当我试图将希伯来字符串分配给变量时,它并没有分配它。例如:
α= 'א'
a =
任何想法为什么?
答案 0 :(得分:2)
Aleph is in UTF-16,matlab以其标准的2字节char
格式表示。它可能不会以这种方式支持它的输入。
您可能必须这样做
a = char(1488); % 1488 is UTF-16 for aleph
然后以UTF-16的某种方式输出它。
如果您想简单地将希伯来语放入图形标题或其他内容,那么您可以直接编写Latex:
title('\aleph')
如果您正在尝试使用Matlab进行文本处理,我认为它会起作用,但您可能无法在Matlab命令窗口中查看字符。
更新:在我的系统上,甚至不支持使用希伯来语编码写入文件:
fid = fopen('c:\temp\chris.txt','w','native','hebrew');
Warning: The encoding 'ISO-8859-8' is not supported.
See the documentation for FOPEN.
但是如果你设置了希伯来语,也许你的机器支持它。
答案 1 :(得分:2)
这是我在这种情况下读取/写入文件的方法:
%# some Hebrew characters
hebrewString = repmat(char(1488),1,10); %# 'אאאאאאאאאא'
%# convert and write as bytes
b = unicode2native(hebrewString,'UTF-8');
fid = fopen('file.txt','wb');
fwrite(fid, b, '*uint8');
fclose(fid);
%# read bytes and convert back to Unicode string
fid = fopen('file.txt', 'rb');
b = fread(fid, '*uint8')'; %'
fclose(fid);
str = native2unicode(b,'UTF-8');
%# compare and check
isequal(str,hebrewString)
double(str)
为了显示这个字符串,我们需要通过调用:
让MATLAB知道Unicode字符feature('DefaultCharacterSet','UTF-8');
现在在命令提示符下,您可以尝试:
>> str
str =
אאאאאאאאאא
但是,显示带有TEXT功能的字符串(有人可以确认此answer是否确实按照声明的方式工作了吗?):
hTxt = text(0.1,0.5, str, 'FontName','David', 'FontSize',30);
set(hTxt, uisetfont(hTxt))
我甚至检查过正确的字体是否可用:
>> fontsNames = fontinfo();
>> idx = ~cellfun(@isempty, strfind(lower(fontsNames),'david'));
>> fontsNames(idx)'
ans =
'David'
'David Bold'
'David Regular'
'David Transparent'
另一方面,正如我在previous answer of mine中所展示的那样,在GUI中显示此文本的解决方案是使用Java(MATLAB UICONTROL基于Java Swing组件):
figure('Position',[300 300 500 50]), drawnow
uicontrol('Style','text', 'String',str, ...
'Units','normalized', 'Position',[0 0 1 1], ...
'FontName','David', 'FontSize',30);
(请注意,通过使用UICONTROL,即使常规的'Arial'字体显示正确的输出!)