Limiting export of digits in mlreport.gen.dom*?

4 ビュー (過去 30 日間)
Karlie Hornberger
Karlie Hornberger 2017 年 6 月 1 日
コメント済み: Karlie Hornberger 2017 年 6 月 2 日
I'm using mlreport.gen.dom* to fill calculations into a word template with holes. For example:
hole1=1.535;
hole2=hole1*4000;
import mlreportgen.dom.*;
namethedoc='testing'
type = 'docx';
calltheform='must have a form to run this sample'
rpt = Document(namethedoc,type,calltheform);
open(rpt);
while(~strcmp(rpt.CurrentHoleId,'#end#'))
switch(rpt.CurrentHoleId)
case 'Hole1'
append(rpt,hole1);
case 'Hole2'
append(rpt,hole2);
end
moveToNextHole(rpt);
end
close(rpt);
docview('testing');
When running this on its own, none of the numbers round when they appear in Word (they report too many decimal points). To combat that, I added a separate rounding.m file for rounding and changed the cases to append(rpt,rounding(dx1)). If the number is small (between 0 and 5), I want several decimal points read out, otherwise, the nearest integer is fine. The function, given below, and several variants have not successfully put the rounded number into the document for the 0 to 5 range. It even takes given values, such as 1.535, and makes it into 1.534999999999999999.
function y=rounding(x)
clc
if x>0 && x<5
format short
y=round(x,5,'significant')
fprintf('%5.2f',y)
else
format short
y=round(x)
fprintf('%f',y)
end
end
I've tried with and without the fprintf and several other variations.
Any ideas about how I can limit the display of digits when copying from MATLAB to Word?

採用された回答

Paul Kinnucan
Paul Kinnucan 2017 年 6 月 2 日
編集済み: Paul Kinnucan 2017 年 6 月 2 日
Try this:
import mlreportgen.dom.*
d = Document('FloatingPoint', 'docx');
append(d, Paragraph(rounding(2.129999)));
append(d, Paragraph(rounding(6.5)));
close(d);
rptview(d);
function y=rounding(x)
if x>0 && x<5
format short
y=round(x,5,'significant');
y = sprintf('%5.2f',y);
else
format short
y=round(x);
y = sprintf('%0.0f',y);
end
end
  1 件のコメント
Karlie Hornberger
Karlie Hornberger 2017 年 6 月 2 日
Thank you so much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Report Generator Task Examples についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by