MATLAB Answers

Arabic document

52 views (last 30 days)
Hello Everyone. Please, I want to know if you can read Arabic document in matlab. Arabic is install on my computer, and when I try to read the file it gives me: {'المملكة' 'المغربية'} is that you have an idea please??

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 28 Apr 2011
How are you reading the file, and how are you displaying it? What is your locale set to? What is your font set to?

  3 Comments

Walter Roberson
Walter Roberson on 28 Apr 2011
I was thinking that perhaps Arabic was outside the range of characters representable in MATLAB, but it is not. The chart is at http://en.wikipedia.org/wiki/Arabic_%28Unicode_block%29
Please try
dec2hex(0 + doc{1})
and look to see if the values that were stored look appropriate for the text. If they do, then it is a problem with the displaying of the text rather than the reading of it. If the values look wrong, then you may need to explore the possibility that the file is not UTF-8 encoded.
Walter Roberson
Walter Roberson on 28 Apr 2011
It doesn't help to say "Its not working". Please show the first line of the output of dec2hex(0 + doc{1}) and indicate the unicode code points for the first 16 or so characters you are expecting in the file. Also, please change your 'r' option to 'rt' so that you are working with text instead of binary.
Please also execute this and indicate the output:
fid = fopen('arabe.txt','r');
dec2hex(0 + fread(fid, 32, '*uint8'));
fclose(fid);
Walter Roberson
Walter Roberson on 28 Apr 2011
If that is the entire output, then your file is only 5 bytes long. I need a longer sample than that to debug this problem.
I also still need the first line of the output of dec2hex(0 + doc{1}), and the first few unicode code points of what you are expecting. Unfortunately this forum is not able to support posting arabic directly so you will have to look up the characters in the wikipedia article I referenced and write them down manually.

Sign in to comment.

More Answers (6)

najmaf najma
najmaf najma on 28 Apr 2011
I read the file with:
fid=fopen('arabe.txt','r','n','UTF-8');
doc=textscan(fid,'%s');
fclose(fid);
doc{1}
The result is:
'ااض'
'اي'
'يمضحث'

  0 Comments

Sign in to comment.


najmaf najma
najmaf najma on 28 Apr 2011
no its not working, I use other formats than UTF-8 ', but its not working well. I'm really stuck on this level.

  0 Comments

Sign in to comment.


najmaf najma
najmaf najma on 28 Apr 2011
i use it: fid = fopen('arabe.txt','rt'); dec2hex(0 + fread(fid, 32, '*uint8')) fclose(fid); the result is: { ans =
EF BB BF D8 A7 }
this is the file arabe: ??? ?? ????? ??? ???? ???? ???? ??? ???? ?????
and thank you

  1 Comment

Walter Roberson
Walter Roberson on 28 Apr 2011
I needed you to use
fid = fopen('arabe.txt','r');
dec2hex(0 + fread(fid, 32, '*uint8'));
fclose(fid);
You used 'rt' instead. I don't know if that makes a difference.

Sign in to comment.


najmaf najma
najmaf najma on 28 Apr 2011
sorry, I wanted to send you the file contents of my Arabic, but its not working

  0 Comments

Sign in to comment.


najmaf najma
najmaf najma on 28 Apr 2011
you can use any document to test, for the resulta, I sent you that gives me, it gives me character hexadecimal

  2 Comments

Walter Roberson
Walter Roberson on 28 Apr 2011
Yes, and I need to see _what_ those hexadecimal values are.
Wait -- is the first character of the file 0x0627, 'alif ? If so, then the file appears to be a UTF-8 encoding of a UTF-16 byte stream. The file appears to have been encoded twice!
najmaf najma
najmaf najma on 28 Apr 2011
exactly, the first character is the 'alif'

Sign in to comment.


Walter Roberson
Walter Roberson on 28 Apr 2011
If I am correct about the file having been double-encoded, then:
fid = fopen('arabe.txt','r');
inputtext = char(native2unicode(fread(fid)));
fclose(fid)

  21 Comments

najmaf najma
najmaf najma on 6 May 2011
I use the following code:
{
fid=fopen('arabe.txt','rt');
inputtext = native2unicode(fread(fid,'*uint8'),'UTF-8') .';
fclose(fid);
i=textscan(inputtext,'%s');
}
i sent you an image in your email adress for the changing system.
Walter Roberson
Walter Roberson on 6 May 2011
It appears that najmaf changed the Windows Regional Language settings.
najmaf najma
najmaf najma on 7 May 2011
exactly.
when I change the format parameter in Arabic, the text is afiche

Sign in to comment.

Sign in to answer this question.