Matlab: latex command to output with 4 significant digits or with certain amount of decimals?

做~自己de王妃 提交于 2019-12-13 18:21:55

问题


I want to generate a table for the results in Matlab. I use the symbolic box's latex command. How can I specify the amount of significant digits?

Problem profile

>> results

results =

    0.0025    0.0024    0.0024

>> latex(vpa(sym(results),4))       #THIS SHOULD PRINT with 4 decimals, how?

ans =

\left(\begin{array}{ccc} 0.0025401858540021748922299593687057 & 0.0023686521873358401535369921475649 & 0.0023649304185866526495374273508787 \end{array}\right)

>> vpa(sym(results),4)

ans =

[ 0.00254, 0.002369, 0.002365]

回答1:


I think that syntax for vpa sets the minimum number of significant figures. Did you try setting the variable-precision accuracy?

d1 = digits(4); % records and sets accuracy
latex(vpa(sym(results)))
digits(d1); % restore previous accuracy



回答2:


THANK YOU!

I just created the following nifty function using this (to output transfer functions directly in latex format):

function tf2latex(tf)

[num,den]=tfdata(tf);
syms s
d1 = digits(4); % records and sets accuracy
latex(vpa(poly2sym(cell2mat(num),s)/poly2sym(cell2mat(den),s)))
digits(d1); 

end


来源:https://stackoverflow.com/questions/21437777/matlab-latex-command-to-output-with-4-significant-digits-or-with-certain-amount

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!