hebrew in the command line - matlab [duplicate]
Possible Duplicate:
text('hebrew strin开发者_如何学编程g') 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?
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.
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))
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);
(note that by using UICONTROL, even the regular 'Arial' font shows the correct output!)
精彩评论