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

57 ビュー (過去 30 日間)
suppose a text file="hello" how it ll convert to utf-8 or utf-16

回答 (4 件)

Tom Anderson
Tom Anderson 2016 年 5 月 2 日
編集済み: Tom Anderson 2016 年 5 月 2 日
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 2013 年 2 月 25 日
編集済み: Thorsten 2013 年 2 月 25 日
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 2021 年 2 月 19 日
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 2013 年 2 月 25 日
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()

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by