How to get character encoding for netCDF attributes

3 次查看(过去 30 天)
Hello guys,
I have to write global attributes in netCDF files that may contains some special characters (such as "à" and "é" coming from french words). However, the encoding of these characters differ from a system to another. For instance, on my Windows desktop, Matlab seems to encode the characters using Windows-1252 and on a different system on Unix, Matlab writes them in UTF-8 (even if feature('DefaultCharacterSet') return "US-ASCII" in that case). It results that I can get weird characters when I read attributes that were written on an other system.
So, I would like to know if there is a way to know what character encoding Matlab will use (or was used) to write netCDF attributes and if it is possible to select the character encoding to read/write these attributes with Matlab.

回答(1 个)

PierreMB
PierreMB 2019-4-23
I may have found an answer here :
So, it says that since the version 2017a, Matlab has changed the way it manipulates non-ASCII characters. From what I have tested, it seems that before 2017a the encoding was in ISO-8859-1 (or ANSI/Windows-1252) and since 2017a, it changed to UTF-8 no matter on what system it is or what feature('DefaultCharacterSet') says.
If someone else can confirm (or invalidate) this, that would be great!

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by