About writing text file! (russian word)

5 views (last 30 days)
swe lin htoo aung htoo aung
Edited: per isakson on 18 Mar 2019
I built some gui. In this gui, I made some calculations and got results. For example, result is assigned to variable S1. I wrote this result to text file.
fid = fopen('newfile.txt','w');
S2= char(S1);
fprintf(fid, '%s', S2);
fclose(fid);
winopen('newfile.txt')
As that code, if we get S1= 65, the word 'A' will be written in text file. This was OK when i tested it.
But when I tested with ASCII code for russian word, the suitable word was not written in text file. Please point me out this problem.

Answers (2)

Walter Roberson
Walter Roberson on 13 Jun 2011
fid = fopen('newfile.txt','wt','UTF-8');
fwrite(fid, S1, '=>uint8');
fclose(fid)
You might have to go further than that to get the proper characters out. Please see this previous Question in which Arabic was the target language (the techniques are the same.)
  1 Comment
swe lin htoo aung htoo aung
Still problem with this line fid = fopen('newfile.txt','wt','UTF-8');
??? Error using ==> fopen
Invalid machine format.
Error in ==>Project>pbRecognize_Callback at 459
fid = fopen('newfile.txt','w','UTF-8');
Thank you very much.

Sign in to comment.


valentin polishchuk
valentin polishchuk on 17 Mar 2019
Use
fid = fopen('newfile.txt','w','n','UTF-8');
Machine format is the third argument of fopen; encoding is the fourth

Community Treasure Hunt

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

Start Hunting!