I have some complicated codes and I want to convert them in equation format.
After that, I will write them using LaTeX.
I am sharing following part of code:
Dx = hypot(bsxfun(@minus,x,x'),bsxfun(@minus,y,y'));
I have some complicated codes and I want to convert them in equation format.
After that, I will write them using LaTeX.
I am sharing following part of code:
Dx = hypot(bsxfun(@minus,x,x'),bsxfun(@minus,y,y'));
The Matlab function latex converts symbolic functions to LaTeX code (see https://nl.mathworks.com/help/symbolic/latex.html).
For your example, latex(Dx) returns
\sqrt{\left|{x - \overline{x}}\right|^{2} + \left|{y - \overline{y}}\right|^{2}}
which renders as
Note that you need to declare the variables first (i.e., syms x y).
In case your function is not symbolic, then you need to declare the variables and convert the function using symfun:
>> syms q w
>> Ax = @(q, w) sqrt (q .^ 2 + w .^ 2);
>> g = symfun(Ax,[q w])
>> latex(g)
\sqrt{q^{2} + w^{2}}
symbolic package for Octave). You may need to install and load this toolbox first. See also https://stackoverflow.com/questions/38240367/undefined-function-function-name-for-input-arguments-of-type-double/.
– Marijn
Apr 04 '18 at 14:56
mintedpackage, if you want to automatically generate nicely formated source code from your.mfiles. If that's not what you seek to do, please clarify. – Christoph90 Apr 03 '18 at 08:58