MATLAB Answers

How to change number precision with writestruct

조회 수: 7(최근 30일)
Bruno Luong
Bruno Luong 2021년 5월 14일
댓글: Scott MacKenzie 2021년 5월 16일
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?
  댓글 수: 1
Bruno Luong
Bruno Luong 2021년 5월 14일
If it's not possible, this must be candidate for a frustration thread

댓글을 달려면 로그인하십시오.

채택된 답변

Scott MacKenzie
Scott MacKenzie 2021년 5월 14일
편집: Scott MacKenzie 2021년 5월 14일
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
Scott MacKenzie
Scott MacKenzie 2021년 5월 16일
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.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by