命令行中的希伯来语 - matlab

发布于 2024-12-10 08:50:50 字数 352 浏览 0 评论 0原文

可能的重复:
文本('希伯来字符串')matlab

shalom
我正在尝试在 matlab 中使用希伯来字符串。但是当我尝试将希伯来字符串分配给变量时,它不会分配它。例如:

<块引用>

a='א'

一=

有什么想法吗?

Possible Duplicate:
text('hebrew string') matlab

shalom
I am trying to work with hebrew strings in matlab. but when I am trying to assign hebrew string to a variable, it doens't assign it. for example:

a='א'

a =

any ideas why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

筱果果 2024-12-17 08:50:50

Aleph 采用 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. 

但如果您设置了希伯来语语言,也许您的机器支持它。

Aleph is in UTF-16, which matlab represents with its standard 2 byte char format. It probably doesn't support input of it this way.

You probably have to do

 a = char(1488);  % 1488 is UTF-16 for aleph

And then output it some way readable by UTF-16.

If you're trying to simply put Hebrew into a figure title or something, then you can directly write Latex like this:

 title('\aleph')

If you are trying use Matlab for text processing, I think it will work but you might not be able to view the characters in the Matlab command window.

Update: On my system even writing to a file in the Hebrew encoding is not supported:

 fid = fopen('c:\temp\chris.txt','w','native','hebrew');
 Warning: The encoding 'ISO-8859-8' is not supported.
 See the documentation for FOPEN. 

But maybe your machine supports it if you have Hebrew languages set up.

椵侞 2024-12-17 08:50:50

在这种情况下,我将执行以下操作来读取/写入文件:

%# 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 =
אאאאאאאאאא

但是,使用 < 显示字符串a href="http://www.mathworks.com/help/techdoc/ref/text.html" rel="nofollow noreferrer">TEXT 函数失败(有人可以确认这个答案实际上如声称的那样工作吗?)

hTxt = text(0.1,0.5, str, 'FontName','David', 'FontSize',30);
set(hTxt, uisetfont(hTxt))

TEXT

我什至检查了正确的字体是否可用:

>> fontsNames = fontinfo();
>> idx = ~cellfun(@isempty, strfind(lower(fontsNames),'david'));
>> fontsNames(idx)'
ans = 
    'David'
    'David Bold'
    'David Regular'
    'David Transparent'

另一方面,正如我在 我之前的回答 ,在 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

(请注意,通过使用UICONTROL,即使是常规的“Arial”字体也能显示正确的输出!)

This is what I would do to read/write to files in this case:

%# 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)

For displaying this string, we need to make MATLAB aware of Unicode characters by calling:

feature('DefaultCharacterSet','UTF-8');

Now on the command prompt you can try:

>> str
str =
אאאאאאאאאא

However, displaying the string with the TEXT function failed (Can someone confirm if this answer actually works as claimed?):

hTxt = text(0.1,0.5, str, 'FontName','David', 'FontSize',30);
set(hTxt, uisetfont(hTxt))

TEXT

I even checked that the correct fonts are available:

>> fontsNames = fontinfo();
>> idx = ~cellfun(@isempty, strfind(lower(fontsNames),'david'));
>> fontsNames(idx)'
ans = 
    'David'
    'David Bold'
    'David Regular'
    'David Transparent'

On the other hand, and as I showed in a previous answer of mine, the solution to showing this text in a GUI is to use Java (MATLAB UICONTROL is based on Java Swing components):

figure('Position',[300 300 500 50]), drawnow
uicontrol('Style','text', 'String',str, ...
    'Units','normalized', 'Position',[0 0 1 1], ...
    'FontName','David', 'FontSize',30);

UICONTROL

(note that by using UICONTROL, even the regular 'Arial' font shows the correct output!)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文