Effacer les filtres
Effacer les filtres

hello, how to convert a text file into utf-8 or utf -16 in matlab.Is there any function ?pls help me fnds..

63 vues (au cours des 30 derniers jours)
suppose a text file="hello" how it ll convert to utf-8 or utf-16

Réponses (4)

Tom Anderson
Tom Anderson le 2 Mai 2016
Modifié(e) : Tom Anderson le 2 Mai 2016
In Windows, the MATLAB Editor/Debugger does not currently (as of 2016) save in UTF-8, but in ANSI. It will actually load a UTF-8 file but if it's saved, the encoding is changed to ANSI. And it appears that this is the way it will be for some time to come. There are hints that the Mac version will allow saving .m files in UTF-8 in the 2016 release notes, but for now they are not saying anything firm about when they will make this change for Windows. As far as I can tell, UTF-8 is now (since 2014) supported in every other area of MATLAB, from Figures to the GUI.
Just not in saving files in the editor. But keep your eyes open; One day, in keeping in this unicode internationalisation trend, maybe in the next decade or two, Mathworks might also allow the editor to save in UTF-8 or unicode format under Windows.
Note that this is what I heard from Mathworks product support on this issue: "I am writing in reference to your Technical Support Case #01940322 regarding 'Editor/Debugger can't save in UTF-8 format'. Thank you for your email. Our developer are aware of this behavior and they may incorporate this in any future release of MATLAB."

Thorsten
Thorsten le 25 Fév 2013
Modifié(e) : Thorsten le 25 Fév 2013
feature('DefaultCharacterSet', 'UTF8')
will change the encoding to UTF-8. You can put the line above in your startup.m file.

MathWorks Support Team
MathWorks Support Team le 19 Fév 2021
As of R2020a, MATLAB defaults to saving new plain text files using UTF-8. You can select a different encoding with the Save As dialog.
As of R2020a, UTF-16 (LE and BE) is also supported, but the encoding must be specified when writing a file:
fid = fopen('utf16_file.txt', 'w', 'n', 'utf-16le')
When opening existing files, the Editor and functions like type or fopen automatically determine the current encoding.

Walter Roberson
Walter Roberson le 25 Fév 2013
When you fopen() a text file you can specify the character set encoding you want it to be written in.
Sometimes it turns out to be necessary to work with unicode2native() or native2unicode()

Community Treasure Hunt

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

Start Hunting!

Translated by