MATLAB: How to output a decimal format in the use of command Latex

convertmatrix

Hi, there? I tried to convert a matrix (calculated by Matlab) to a LaTex format such that I can directly apply it to my LaTex document, I used the _ * Latex*_ command, but the output is not decimal format, how to make its output is in decimal format?
The code and its corresponding output is shown as follows:
W =
0.4237 0.3373 0.2390 0
0.6603 0.3397 0 0
0.6877 0 0 0.3123
0 0 0.6181 0.3819
>> latex_table = latex(sym(W))
latex_table =
\left(\begin{array}{cccc} \frac{4237}{10000} & \frac{3373}{10000} & \frac{239}{1000} & 0\\ \frac{6603}{10000} & \frac{3397}{10000} & 0 & 0\\ \frac{6877}{10000} & 0 & 0 & \frac{3123}{10000}\\ 0 & 0 & \frac{6181}{10000} & \frac{3819}{10000} \end{array}\right)

Best Answer

Use the vpa funciton:
latex_table = latex(sym(vpa(W)))
latex_table = \left(\begin{array}{cccc} 0.4237 & 0.3373 & 0.239 & 0\\ 0.6603 & 0.3397 & 0 & 0\\ 0.6877 & 0 & 0 & 0.3123\\ 0 & 0 & 0.6181 & 0.3819 \end{array}\right)
I’m no LaTeX expert, but from my experience, you have to begin and end your LaTeX calls with $.