A Byte order mark (BOM) inserted by writetable (xml export and xlsx export), why?

6 ビュー (過去 30 日間)
Stephane
Stephane 2024 年 3 月 19 日
編集済み: Stephane 2024 年 3 月 19 日
A byte order mark (BOM) is inserted by writetable when exporting a table to a CSV file, using this command:
writetable(T, ‘T.csv’, 'Encoding', 'UTF-8')
This zero-length BOM character (U+FEFF) is seen in the following image taken from a text editor (showing invisibles), the BOM being pictured as a red dot (invisible character) at the very first position of the file content.
I can understand the logic behind inserting this BOM (helping read a text file with a specific encoding), even if I prefer the BOM addition to be optional.
What I don’t understand is the rationale of inserting a BOM in each tag of the same table, exported in XML format (see the red dots before each of the UNIX_TIMESTAMP tags).
It doesn't make sense to me. The UNIX_TIMESTAMP tags should not have a BOM, right? Or is there a particular reason?
PS: what would be the most efficient way to get rid of the BOM(s)?
PS2: the BOMs are also present in the UNIX_TIMESTAMP cell (cell A1) when exporting to XLSX. This is not right too. It should only contain a string with ASCII characters in the current case.
Many thanks
  2 件のコメント
Walter Roberson
Walter Roberson 2024 年 3 月 19 日
Huh. Strange.
Stephane
Stephane 2024 年 3 月 19 日
I digged further, and the problem does not come from writetable, my bad. Will prepare an answer.

サインインしてコメントする。

採用された回答

Stephane
Stephane 2024 年 3 月 19 日
編集済み: Stephane 2024 年 3 月 19 日
The problem does not come from writetable actually, but from a hidden character in the char values contained in the cell array defining VariableNames.
... 3 hours on this ... but at least I solved it :0
'UNIX_TIMESTAMP' contained an invisible character at the start of the char.
t_equal_cell = table(timestamp, x_g, VariableNames={'UNIX_TIMESTAMP','Gx'});

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOther Formats についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by