Arabic writing in a text file

5 次查看(过去 30 天)
najmaf najma
najmaf najma 2011-5-31
Hello. I want to record Arabic characters into a text file in matlab. my problem is as follows: I open the file Arabic words and I compare this document with those of another, and in the end I want to save those who are different in another document, but its not working.
  2 个评论
Walter Roberson
Walter Roberson 2011-5-31
Insufficient information about what you are doing.
Do you have this working for a non-arabic test set, to be sure that the problem is the arabic and not your algorithm?
najmaf najma
najmaf najma 2011-5-31
yes i do it for the english document.
this my code:
{
words= 'document.txt';
words_id=fopen(words,'r');
inputtext = native2unicode(fread(words_id,'*uint8'),'UTF-8') .';
fclose(words_id);
words=textscan(inputtext,'%s');
sw_file= 'stopwords.txt';
sw_id=fopen(sw_file,'r');
inputtext = native2unicode(fread(sw_id,'*uint8'),'UTF-8') .';
fclose(sw_id);
sw=textscan(inputtext,'%s');
fid = fopen('nv.txt', 'wt');
for i=1:length(words{1})
w=words{1}{i};
r = strcmp(w,sw{1});
if(sum(r)==0)
fprintf(fid,'%s\n',w);
end
end
fclose(fid);
}

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2011-5-31
If you need to use native2unicode when you read the data in, you might need to use unicode2native() to prepare the data to be written out.
NL = sprintf('\n'); %newline
And open nv.txt with 'w' instead of 'wt'.
Then instead of fprintf(),
fwrite(fid, unicode2native([w NL], 'UTF-8'));

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by