问题
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