insert a matlab matrix into latex automatically
March 31st, 2006 by Lawrence David
manually writing out matlab matrices in latex is really tedious. here’s how to save yourself the time:
assume you have some matrix L
>> s = sym(L);
>> v = vpa(s,5); # assign numerical precision
>> latex(v)
matlab should now spit out the latex source code that you can directly copy into your .tex file.
Could you help me in inserting a matrix within a line…all my efforts are producing the matrix in the next line. Thanks in advance.
Thanks, I didn’t know about this feature. Very useful.
[...] http://desk.stinkpot.org:8080/tricks/index.php/2006/03/insert-a-matlab-matrix-into-latex-automatical… [...]
Very helpful, thank you!!
Doesn’t work perfectly for me on 2010a.
The output precision is the same.
vpa(A,3) : I have 0.333
but after latex(vpa(A,3))
I have 0.33333333333333
Try this:
digits(4); //this changes the output precision
s=sym(A,’d'); //the ‘d’ flag makes sure the sym output is in decimal form
latex(s);
worked for me!