fprintf or fwrite non ASCII characters

조회 수: 16 (최근 30일)
Daniele Venanzetti
Daniele Venanzetti 2021년 6월 3일
댓글: Daniele Venanzetti 2021년 6월 4일
Hi everyone,
I am trying to write some strings on a text but some of them contain σ and μ and they are not written correctly in my file when I use either fprintf or fwrite. I tried also to open my file (fopen) with different encondings but nothing changed. Below you find my most significant attempts:
SheetName = 'example';
text_file = fopen(strcat(SheetName, '.txt'), 'w+','n','windows-1253');
fprintf(text_file,'%c', 'σ'); % prints ?
fprintf(text_file,'%s', char(963)); % prints ó
fprintf(text_file, '\x03c3'); % prints ó
fwrite(text_file, 'σ'); % prints ?
fwrite(text_file, char(963)); % prints ÿ
If I don't put the encoding 'windows-1253' I get even worse results: second and third line print a small square.
I have also read that it could depend on my OS but honestly I don't get why. Anyway, I have Windows 10 Pro.
Could you help me out with this? Thanks in advance!
  댓글 수: 6
Stephen23
Stephen23 2021년 6월 3일
편집: Stephen23 2021년 6월 3일
@Daniele Venanzetti: what OS are you using?
Perhaps you could try using these FOPEN options:
fopen('test.txt','w','n','UTF-8')
Daniele Venanzetti
Daniele Venanzetti 2021년 6월 3일
I have Windows 10 Pro. I tried your fopen options and I got this:

댓글을 달려면 로그인하십시오.

답변 (1개)

Constantino Carlos Reyes-Aldasoro
Have you tried using TeX formatting? I.e. \alpha \sigma \mu
https://uk.mathworks.com/help/matlab/creating_plots/greek-letters-and-special-characters-in-graph-text.html
  댓글 수: 3
Constantino Carlos Reyes-Aldasoro
Have you tried using ascii values? e.g.
strcat('a=',181)
ans = 'a=µ'
Daniele Venanzetti
Daniele Venanzetti 2021년 6월 4일
It works only on the command window but I need to write it in a text.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by