MATLAB Answers

How to print greek letters like 'µ' in fprintf to file handle?

36 views (last 30 days)
Aayush Singla
Aayush Singla on 26 Nov 2019
Answered: Aayush Singla on 26 Nov 2019
Hello,
I am using MATLAB R2018b and want to print greek letters like 'µ' to a text/ini file from matlab using fprintf.
I have read couple of old threads which say it is not possible in earlier releases.
MATLAB 2018b returns true for
isletter('µ')
I am just trying out simple string like
fprintf(fhandle,'16.0µm');
It prints out 16.0xB5m in the file. I have already tried out escape characters like
fprintf(fhandle,'16.0 \mu m \n');
fprintf(fhandle,'16.0 \\mu m \n');
fprintf(fhandle,'16.0 \xB5 m \n');
However, none of these seem to work.
Is there any idea of how to solve this issue or a workaround for the problem?
Is the issue addressed in future releases of MATLAB ?

  0 Comments

Sign in to comment.

Accepted Answer

Stephan
Stephan on 26 Nov 2019
Edited: Stephan on 26 Nov 2019
fileID = fopen('testFile.txt','w')
fprintf(fileID,['16.0', char(181), 'm']);
fclose(fileID)
testFile.PNG

  0 Comments

Sign in to comment.

More Answers (1)

Aayush Singla
Aayush Singla on 26 Nov 2019
Edit:
fprintf(fhandle,'16.0µm'); works too but the changes are visible only after the file handle is closed.
If the file handle is still open, xB5 is visible.
Thanks for the workaround too.

  0 Comments

Sign in to comment.

Sign in to answer this question.

Products


Release

R2018b