How to publish symbolic matrices in latex format in MATLAB?

조회 수: 27 (최근 30일)
Elie Hatem
Elie Hatem 2020년 6월 2일
편집: Elie Hatem 2020년 6월 2일
Hello,
I have a project in which I have to publush symbolic matrices in latex format.
An example of a matrix is the following:
J1 =
[ 1, 0, a]
[ 1, 0, -a]
[ cos(beta_3s), sin(beta_3s), b*sin(beta_3s)]
If I try to publish it in latex format, I get the same eqiation as above:
\begin{document}
\color{lightgray} \begin{verbatim}
J1 =
[ 1, 0, a]
[ 1, 0, -a]
[ cos(beta_3s), sin(beta_3s), b*sin(beta_3s)]
\end{verbatim} \color{black}
As you can see, the matrix is not publlished in the neat way that latex can actually write the matrix.
Moreover, if I tried solving the problem using a function that I created as follows:
function lat = tex(input)
lat=['$',latex(input),'$'];
end
This outputs the desired code which is: '$\left(\begin{array}{ccc} -\sin\left(\beta _{\mathrm{1s}}\right) & \cos\left(\beta _{\mathrm{1s}}\right) & b\,\sin\left(\beta _{\mathrm{1s}}\right)\\ \sin\left(\beta _{\mathrm{2s}}\right) & -\cos\left(\beta _{\mathrm{2s}}\right) & b\,\sin\left(\beta _{\mathrm{2s}}\right)\\ -\sin\left(\beta _{\mathrm{3c}}\right) & \cos\left(\beta _{\mathrm{3c}}\right) & c\,\sin\left(\beta _{\mathrm{3c}}\right) \end{array}\right)$'
However, if I try to publish the script in latex format using the function above and the disp function, (disp(tex(J1))), I get the following output in the published .tex file:
\begin{document}
\color{lightgray} \begin{verbatim}$\left(\begin{array}{ccc} 1 & 0 & a\\ 1 & 0 & -a\\ \cos\left(\beta _{\mathrm{3s}}\right) & \sin\left(\beta _{\mathrm{3s}}\right) & b\,\sin\left(\beta _{\mathrm{3s}}\right) \end{array}\right)$
\end{verbatim} \color{black}
So as you can see, the code is now published with \begin{verbatim} \end{verbatim} . So, instead of showing the matrix, the latex code will show the code instead.
Is there a way to output the latex code in a way that it will be outside \begin{verbatim} \end{verbatim} and make it display the symbolic matrix?
I am sorry for the long question but I saw some people tried to ask the same question but did not find an answer. So, I tried to detail my problem as much as possible.
Thank you for your time.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 6월 2일
You may try Live scripts. It renders the symbolic matrices in mathematical notation and allows you to get latex code directly. For example, run this code in Live script
syms a beta_3s b
x = [1 0 a;
1 0 -a;
cos(beta_3s) sin(beta_3s) b*sin(beta_3s)]
right-click on the output and click "copy as Latex". It gives the following latex code
\left(\begin{array}{ccc}
1 & 0 & a\\
1 & 0 & -a\\
\mathrm{cos}\left(\beta_{\textrm{3s}} \right) & \mathrm{sin}\left(\beta_{\textrm{3s}} \right) & b\,\mathrm{sin}\left(\beta_{\textrm{3s}} \right)
\end{array}\right)
which is rendered like this
  댓글 수: 1
Elie Hatem
Elie Hatem 2020년 6월 2일
편집: Elie Hatem 2020년 6월 2일
Thank you so much for your answer. The main issue is that the user of the final code will be able to choose a .txt table. Then, from that table, all the computations will be done and published to a .tex file . So, everything should be done automaticallly and each time, the table may change. An example of such a table is attached above. Moreover, please note that the beta angles are not inputed by the user, but generated automatically by MATLAB based on the first column of the table (if there is a 'f' in the first column of the stable, this means that the robot has a fixed wheel, and the beta angle for that wheel will be null. However, if there is a 's' or a 'c', this means that the wheel is a steerable wheel or castor wheel respectively and a symbolic beta angle will be generated in both of these cases)
Thank you

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 External Language Interfaces에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by