How to change number precision with writestruct

6 visualizaciones (últimos 30 días)
Bruno Luong
Bruno Luong el 14 de Mayo de 2021
Comentada: Scott MacKenzie el 16 de Mayo de 2021
The number of significant digits of writestruct is quite limited, as showed by this example
s=struct('pi',pi);
writestruct(s,'pi.xml');
type pi.xml
<?xml version="1.0" encoding="UTF-8"?> <struct> <pi>3.1416</pi> </struct>
Does anyone know how to change/control/increase it?

Respuesta aceptada

Scott MacKenzie
Scott MacKenzie el 14 de Mayo de 2021
Editada: Scott MacKenzie el 14 de Mayo de 2021
s=struct('pi', num2str(pi, 15)); % pi with 15 significant figures
writestruct(s, 'pi.xml');
type pi.xml
Output:
<?xml version="1.0" encoding="UTF-8"?>
<struct>
<pi>3.141592653589793</pi>
</struct>
  4 comentarios
Bruno Luong
Bruno Luong el 16 de Mayo de 2021
Thanks for the effort Scott.
To me still not ideal. This XML is used as interface with other SW (otherwise I won't bother with XML). It a pain to minimze the precision output.
Scott MacKenzie
Scott MacKenzie el 16 de Mayo de 2021
Yes, I see your point. I studied the documentation and clearly writestruct is not intended for numeric variables. The focus is on text, and xml in particular. Good luck.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by